-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
37 lines (36 loc) · 884 Bytes
/
auth.ts
File metadata and controls
37 lines (36 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
import { dbClient } from "./database/client";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [Google],
pages: {
signIn: "/login",
},
callbacks: {
async session({ session, token, user }) {
let userDbData;
if (token && token.email) {
userDbData = await dbClient.users.upsert({
where: { email: token.email },
update: {
name: token.name,
email: token.email,
image: token.picture,
},
create: {
name: token.name,
email: token.email,
image: token.picture,
},
});
}
return {
...session,
user: {
...session.user,
id: userDbData?.id,
},
};
},
},
});