From c90e0c785915765e41fa7fcba7fed833d36f0bae Mon Sep 17 00:00:00 2001 From: Dawood Mehmood Date: Fri, 7 Feb 2025 15:56:01 +0500 Subject: [PATCH 1/2] python backend changes --- .../crowd-fund-analysis/cf_analysis_agent/.env.example | 2 +- ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py | 10 ++-------- .../cf_analysis_agent/utils/env_variables.py | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/ai-agents/crowd-fund-analysis/cf_analysis_agent/.env.example b/ai-agents/crowd-fund-analysis/cf_analysis_agent/.env.example index 806fdf0a9..d41e27001 100644 --- a/ai-agents/crowd-fund-analysis/cf_analysis_agent/.env.example +++ b/ai-agents/crowd-fund-analysis/cf_analysis_agent/.env.example @@ -11,4 +11,4 @@ SERPER_API_KEY= LINKEDIN_EMAIL= LINKEDIN_PASSWORD= SECRET_KEY=anything -ADMIN_CODES= \ No newline at end of file +ADMIN_CODES=Robin-123456, Dawood-234567 \ No newline at end of file diff --git a/ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py b/ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py index 23f5e3360..0fc0418b6 100644 --- a/ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py +++ b/ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py @@ -219,10 +219,7 @@ def authenticate(): code = data.get("code") if not code: - return jsonify({ - "status": "error", - "message": "Code is required" - }), 400 + return jsonify({"status": "error", "message": "Code is required"}), 400 if code in ADMIN_CODES: hashed_key = generate_hashed_key(code) @@ -232,10 +229,7 @@ def authenticate(): "key": hashed_key }), 200 - return jsonify({ - "status": "error", - "message": "Invalid code" - }), 401 + return jsonify({"status": "error", "message": "Invalid code"}), 401 if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/ai-agents/crowd-fund-analysis/cf_analysis_agent/utils/env_variables.py b/ai-agents/crowd-fund-analysis/cf_analysis_agent/utils/env_variables.py index 089812fd4..ad7edb21b 100644 --- a/ai-agents/crowd-fund-analysis/cf_analysis_agent/utils/env_variables.py +++ b/ai-agents/crowd-fund-analysis/cf_analysis_agent/utils/env_variables.py @@ -12,4 +12,4 @@ LINKEDIN_EMAIL = os.getenv("LINKEDIN_EMAIL") LINKEDIN_PASSWORD = os.getenv("LINKEDIN_PASSWORD") SECRET_KEY = os.getenv("SECRET_KEY") -ADMIN_CODES = set(os.getenv("ADMIN_CODES", "").split(",")) \ No newline at end of file +ADMIN_CODES = set(code.strip() for code in os.getenv("ADMIN_CODES", "").split(",")) \ No newline at end of file From 932ef303583b78ef642433584cf8256a752f818c Mon Sep 17 00:00:00 2001 From: Dawood Mehmood Date: Fri, 7 Feb 2025 15:56:11 +0500 Subject: [PATCH 2/2] frontend changes --- .../src/components/auth/PrivateWrapper.tsx | 18 ++++++++++++++++++ .../components/projects/ProductDetailsPage.tsx | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 insights-ui/src/components/auth/PrivateWrapper.tsx diff --git a/insights-ui/src/components/auth/PrivateWrapper.tsx b/insights-ui/src/components/auth/PrivateWrapper.tsx new file mode 100644 index 000000000..fdbaac3c1 --- /dev/null +++ b/insights-ui/src/components/auth/PrivateWrapper.tsx @@ -0,0 +1,18 @@ +'use client'; + +import { isAdmin } from '@/util/auth/isAdmin'; +import { ReactNode, useEffect, useState } from 'react'; + +interface ClientOnlyAdminProps { + children: ReactNode; +} + +export default function PrivateWrapper({ children }: ClientOnlyAdminProps) { + const [admin, setAdmin] = useState(false); + + useEffect(() => { + setAdmin(isAdmin()); + }, []); + + return admin ? <>{children} : null; +} diff --git a/insights-ui/src/components/projects/ProductDetailsPage.tsx b/insights-ui/src/components/projects/ProductDetailsPage.tsx index db8cb6e47..92b604b9f 100644 --- a/insights-ui/src/components/projects/ProductDetailsPage.tsx +++ b/insights-ui/src/components/projects/ProductDetailsPage.tsx @@ -5,6 +5,7 @@ import { getReportName } from '@/util/report-utils'; import Link from 'next/link'; import React from 'react'; import RadarChart from '../ui/RadarChart'; +import PrivateWrapper from '../auth/PrivateWrapper'; interface ProjectDetailPageProps { projectId: string; @@ -38,7 +39,9 @@ export default function ProjectDetailPage({ projectId, initialProjectDetails, pr
- + + +

{initialProjectDetails.name}

@@ -84,7 +87,9 @@ export default function ProjectDetailPage({ projectId, initialProjectDetails, pr
{getReportName(reportType)}
- + + +
{report.summary}