Skip to content

Commit ab910d9

Browse files
committed
Add logout button
1 parent c1692a9 commit ab910d9

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

catalog-analytics/app/analytics-content.tsx

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from "lucide-react";
2222
import Image from "next/image";
2323
import { getAssetPath } from "@/lib/utils";
24+
import type { User } from '@vector-institute/aieng-auth-core';
2425

2526
// Types
2627
interface RepoSnapshot {
@@ -113,7 +114,11 @@ type SortDirection = "asc" | "desc";
113114
type ActiveTab = "github" | "pypi";
114115
type PyPIFilter = "all" | "tool" | "bootcamp" | "applied-research";
115116

116-
export default function AnalyticsPage() {
117+
interface AnalyticsPageProps {
118+
user: User | null;
119+
}
120+
121+
export default function AnalyticsPage({ user }: AnalyticsPageProps) {
117122
// Load data dynamically to ensure fresh data during development
118123
const [historicalData, setHistoricalData] = useState<HistoricalData | null>(null);
119124
const [pypiData, setPypiData] = useState<PyPIHistoricalData | null>(null);
@@ -126,6 +131,15 @@ export default function AnalyticsPage() {
126131
const [activeTab, setActiveTab] = useState<ActiveTab>("github");
127132
const [pypiFilter, setPypiFilter] = useState<PyPIFilter>("all");
128133

134+
const handleLogout = async () => {
135+
try {
136+
await fetch('/analytics/api/auth/logout', { method: 'POST' });
137+
window.location.href = '/analytics/login';
138+
} catch (error) {
139+
console.error('Logout failed:', error);
140+
}
141+
};
142+
129143
useEffect(() => {
130144
const loadData = async () => {
131145
try {
@@ -437,21 +451,35 @@ export default function AnalyticsPage() {
437451
</p>
438452
</div>
439453
</div>
440-
{historicalData?.last_updated && (
441-
<div className="hidden md:flex items-center gap-2 text-white/90">
442-
<Calendar className="w-5 h-5" />
443-
<div className="text-right">
444-
<div className="text-xs uppercase tracking-wide opacity-80">
445-
Last Updated
446-
</div>
447-
<div className="text-sm font-medium">
448-
{new Date(historicalData.last_updated)
449-
.toISOString()
450-
.split("T")[0]}
454+
<div className="flex items-center gap-4">
455+
{historicalData?.last_updated && (
456+
<div className="hidden lg:flex items-center gap-2 text-white/90">
457+
<Calendar className="w-5 h-5" />
458+
<div className="text-right">
459+
<div className="text-xs uppercase tracking-wide opacity-80">
460+
Last Updated
461+
</div>
462+
<div className="text-sm font-medium">
463+
{new Date(historicalData.last_updated)
464+
.toISOString()
465+
.split("T")[0]}
466+
</div>
451467
</div>
452468
</div>
453-
</div>
454-
)}
469+
)}
470+
{user && (
471+
<div className="text-right">
472+
<p className="text-xs text-white/70 uppercase tracking-wide">Signed in as</p>
473+
<p className="text-sm font-semibold bg-gradient-to-r from-vector-magenta to-vector-violet bg-clip-text text-transparent">{user.email}</p>
474+
</div>
475+
)}
476+
<button
477+
onClick={handleLogout}
478+
className="px-4 py-2 text-sm font-semibold text-white bg-gradient-to-r from-slate-600 to-slate-700 hover:from-vector-magenta hover:to-vector-violet rounded-lg shadow-sm hover:shadow-md transition-all duration-200"
479+
>
480+
Logout
481+
</button>
482+
</div>
455483
</motion.div>
456484
</div>
457485
</div>
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import { NextRequest, NextResponse } from 'next/server';
1+
import { NextResponse } from 'next/server';
22
import { destroySession } from '@/lib/session';
3-
import { authConfig } from '@/lib/auth-config';
43

54
export const dynamic = 'force-dynamic';
65

7-
export async function GET(request: NextRequest) {
6+
export async function POST() {
87
try {
9-
// Destroy the session
108
await destroySession();
11-
12-
// Redirect to post-logout URI or base URL
13-
const redirectUri = authConfig.postLogoutRedirectUri || new URL(request.url).origin;
14-
return NextResponse.redirect(redirectUri);
9+
return NextResponse.json({ success: true });
1510
} catch (error) {
1611
console.error('Logout error:', error);
17-
return NextResponse.json({ error: 'Logout failed' }, { status: 500 });
12+
return NextResponse.json({ error: 'Failed to logout' }, { status: 500 });
1813
}
1914
}

catalog-analytics/app/page.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ export default async function Home() {
99
redirect('/login');
1010
}
1111

12-
return <AnalyticsContent />;
12+
const user = session.user;
13+
14+
return <AnalyticsContent user={user} />;
1315
}

0 commit comments

Comments
 (0)