summaryrefslogtreecommitdiff
path: root/frontend/app/api/logout/route.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/api/logout/route.ts')
-rw-r--r--frontend/app/api/logout/route.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/frontend/app/api/logout/route.ts b/frontend/app/api/logout/route.ts
new file mode 100644
index 0000000..51de324
--- /dev/null
+++ b/frontend/app/api/logout/route.ts
@@ -0,0 +1,32 @@
1import { NextRequest } from 'next/server';
2import { redirect } from 'next/navigation';
3import { Auth_tinyauth_endpoint, Auth_tinyauth_public_endpoint } from '@/lib/auth_shared';
4
5export async function POST(request: NextRequest) {
6 try {
7 // Get the current session cookie
8 const cookies = request.cookies.getAll();
9 const sessionCookie = cookies.find(cookie => cookie.name.includes('tinyauth-session'));
10
11 if (sessionCookie) {
12 // Call tinyauth logout endpoint to invalidate the session
13 const logoutResponse = await fetch(`${Auth_tinyauth_endpoint()}/auth/logout`, {
14 method: 'POST',
15 headers: {
16 'Cookie': `${sessionCookie.name}=${sessionCookie.value}`
17 }
18 });
19
20 // Note: We don't need to check the response status as we'll redirect anyway
21 }
22
23 // Redirect to the public logout endpoint which should clear cookies client-side
24 const publicLogoutUrl = `${Auth_tinyauth_public_endpoint()}/auth/logout`;
25 return Response.redirect(publicLogoutUrl, 302);
26
27 } catch (error) {
28 console.error('Logout error:', error);
29 // Even if logout fails, redirect to home
30 return redirect('/');
31 }
32} \ No newline at end of file