Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/mobile auth #772

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets wait for this to be solved

const body = await request.json();
nimit9 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading