@@ -35,19 +35,20 @@ function getNextAuthOptions(prisma: PrismaClient) {
35
35
return Promise . resolve ( token ) ;
36
36
}
37
37
38
- const userId = user . userId ;
39
38
try {
40
39
const prisma = await openConnection ( ) ;
41
- const user = await prisma . user . findUnique ( {
40
+ const dbUser = await prisma . user . findUnique ( {
42
41
where : {
43
- id : userId ,
42
+ id : ( user as Record < string , number > ) . id ,
43
+ email : ( user as Record < string , string > ) . email ?? undefined ,
44
44
} ,
45
- select : { role : true } ,
45
+ select : { id : true , role : true } ,
46
46
} ) ;
47
- token . userId = userId ;
48
- token . role = user ?. role ;
47
+ token . userId = dbUser ?. id ;
48
+ token . role = dbUser ?. role ;
49
49
return token ;
50
50
} catch ( err ) {
51
+ console . error ( err ) ;
51
52
throw Boom . unauthorized ( ) ;
52
53
} finally {
53
54
await closeConnection ( ) ;
@@ -69,9 +70,10 @@ function getNextAuthOptions(prisma: PrismaClient) {
69
70
}
70
71
71
72
const authHandler : NextApiHandler = withAsync (
72
- withDb ( ( req , res ) => {
73
+ withDb ( async ( req , res ) => {
73
74
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 ;
75
77
} ) ,
76
78
) ;
77
79
0 commit comments