Skip to content

Commit

Permalink
added jwt on frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
FearsomeRover committed Nov 21, 2024
1 parent 580070f commit 8b68eb7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ JWT_EXPIRATION="1d"
AUTHSCH_CLIENT_ID=""
AUTHSCH_CLIENT_SECRET=""
BACKEND_PORT=3001
FRONTEND_AUTHORIZED_URL="http://localhost:3000/auth/callback"
16 changes: 16 additions & 0 deletions apps/frontend/src/app/auth/callback/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { cookies } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

export async function GET(request: NextRequest) {
const jwt = request.nextUrl.searchParams.get('jwt');

if (!jwt) {
return new Response('Unauthorized', { status: 401 });
}

cookies().set('jwt', jwt, { path: '/' });

return NextResponse.redirect(new URL('/profile', request.url));
}
10 changes: 10 additions & 0 deletions apps/frontend/src/app/auth/logout/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { cookies } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

export async function GET(request: NextRequest) {
cookies().delete('jwt');

return NextResponse.redirect(new URL('/', request.url));
}

0 comments on commit 8b68eb7

Please sign in to comment.