From a9db646b7d3100af5a45800f04253998bb3429c9 Mon Sep 17 00:00:00 2001 From: Sargam Date: Thu, 20 Jun 2024 02:00:16 +0545 Subject: [PATCH] fix: typo in payload destructuring --- src/app/api/auth/mobile/logout/route.ts | 32 +++++++++++-------------- src/lib/middleware-utils.ts | 4 +++- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/app/api/auth/mobile/logout/route.ts b/src/app/api/auth/mobile/logout/route.ts index 6273acda6..5c546628b 100644 --- a/src/app/api/auth/mobile/logout/route.ts +++ b/src/app/api/auth/mobile/logout/route.ts @@ -3,26 +3,22 @@ import db from '@/db'; export async function POST(request: NextRequest) { try { + // TODO: Get userid from somewhere not body const body = await request.json(); - if (body && body.userId) { - await db.user.update({ - where: { - id: body.userId, - }, - data: { - token: null, - }, - }); - return NextResponse.json({ - message: 'Logout successful', - success: true, - }); - } - return NextResponse.json( - { message: 'User Id not available' }, - { status: 400 }, - ); + await db.user.update({ + where: { + id: body.userId, + }, + data: { + token: null, + }, + }); + return NextResponse.json({ + message: 'Logout successful', + success: true, + }); } catch (error: any) { return NextResponse.json({ error: error.message }, { status: 500 }); } } + diff --git a/src/lib/middleware-utils.ts b/src/lib/middleware-utils.ts index d2cdf3d6f..6943cbb24 100644 --- a/src/lib/middleware-utils.ts +++ b/src/lib/middleware-utils.ts @@ -22,7 +22,9 @@ export const handleMobileAuth = async (request: NextRequestWithAuth) => { if (token) { try { const payload: any = await verifyJWT(token); - request.nextUrl.searchParams.set('userId', payload.id); + // @typo here + const userId = payload.payload.userid; + console.log(userId); return NextResponse.next(); } catch (error) { return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });