Skip to content

Commit

Permalink
fix: typo in payload destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
devsargam committed Jun 19, 2024
1 parent 79e8f99 commit a9db646
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
32 changes: 14 additions & 18 deletions src/app/api/auth/mobile/logout/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}

4 changes: 3 additions & 1 deletion src/lib/middleware-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit a9db646

Please sign in to comment.