Skip to content

Commit

Permalink
Save user to database on account creation
Browse files Browse the repository at this point in the history
  • Loading branch information
vilnor committed May 17, 2024
1 parent 17b5015 commit bea98e0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions frontend/src/app/api/auth/[auth0]/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
import { handleAuth } from '@auth0/nextjs-auth0';
import { handleAuth, handleCallback, Session } from '@auth0/nextjs-auth0';
import { NextApiRequest } from 'next';

export const GET = handleAuth();
const afterCallback = async (
req: NextApiRequest,
session: Session,
) => {
// add the user to our database
await fetch(`${process.env.API_URL}/api/users`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ userId: session.user.sub }),
});
return session;
};

export const GET = handleAuth({
// @ts-ignore
callback: handleCallback({ afterCallback })
});

0 comments on commit bea98e0

Please sign in to comment.