Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new detail page authentication #664

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ SERPER_API_KEY=
LINKEDIN_EMAIL=
LINKEDIN_PASSWORD=
SECRET_KEY=anything
ADMIN_CODES=
ADMIN_CODES=Robin-123456, Dawood-234567
10 changes: 2 additions & 8 deletions ai-agents/crowd-fund-analysis/cf_analysis_agent/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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(","))
ADMIN_CODES = set(code.strip() for code in os.getenv("ADMIN_CODES", "").split(","))
18 changes: 18 additions & 0 deletions insights-ui/src/components/auth/PrivateWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 7 additions & 2 deletions insights-ui/src/components/projects/ProductDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +39,9 @@ export default function ProjectDetailPage({ projectId, initialProjectDetails, pr
<div className="mx-auto max-w-7xl px-6 lg:px-8">
<div className="mx-auto lg:text-center">
<div className="flex justify-end">
<ProjectActionsDropdown projectId={projectId} />
<PrivateWrapper>
<ProjectActionsDropdown projectId={projectId} />
</PrivateWrapper>
</div>
<p className="mt-2 text-pretty text-4xl font-semibold tracking-tight sm:text-5xl">{initialProjectDetails.name}</p>
<div className="max-w-lg mx-auto">
Expand Down Expand Up @@ -84,7 +87,9 @@ export default function ProjectDetailPage({ projectId, initialProjectDetails, pr
</div>
<div className="flex justify-between font-semibold">
<div className="ml-6 text-xl">{getReportName(reportType)}</div>
<ReportActionsDropdown projectId={projectId} report={{ ...report, type: reportType }} />
<PrivateWrapper>
<ReportActionsDropdown projectId={projectId} report={{ ...report, type: reportType }} />
</PrivateWrapper>
</div>
<div className="text-sm py-1">{report.summary}</div>
</dt>
Expand Down