@@ -35,19 +35,20 @@ function getNextAuthOptions(prisma: PrismaClient) {
3535 return Promise . resolve ( token ) ;
3636 }
3737
38- const userId = user . userId ;
3938 try {
4039 const prisma = await openConnection ( ) ;
41- const user = await prisma . user . findUnique ( {
40+ const dbUser = await prisma . user . findUnique ( {
4241 where : {
43- id : userId ,
42+ id : ( user as Record < string , number > ) . id ,
43+ email : ( user as Record < string , string > ) . email ?? undefined ,
4444 } ,
45- select : { role : true } ,
45+ select : { id : true , role : true } ,
4646 } ) ;
47- token . userId = userId ;
48- token . role = user ?. role ;
47+ token . userId = dbUser ?. id ;
48+ token . role = dbUser ?. role ;
4949 return token ;
5050 } catch ( err ) {
51+ console . error ( err ) ;
5152 throw Boom . unauthorized ( ) ;
5253 } finally {
5354 await closeConnection ( ) ;
@@ -69,9 +70,10 @@ function getNextAuthOptions(prisma: PrismaClient) {
6970}
7071
7172const authHandler : NextApiHandler = withAsync (
72- withDb ( ( req , res ) => {
73+ withDb ( async ( req , res ) => {
7374 const options = getNextAuthOptions ( req . db ) ;
74- return NextAuth ( ( req as unknown ) as NextApiRequest , res , options ) ;
75+ const result : unknown = await NextAuth ( ( req as unknown ) as NextApiRequest , res , options ) ;
76+ return result ?? null ;
7577 } ) ,
7678) ;
7779
0 commit comments