-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
55 lines (53 loc) · 1.58 KB
/
Copy pathconfig.ts
File metadata and controls
55 lines (53 loc) · 1.58 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [
Google({
clientId: process.env.AUTH_GOOGLE_ID!,
clientSecret: process.env.AUTH_GOOGLE_SECRET!,
authorization: {
params: {
prompt: "consent",
access_type: "offline",
response_type: "code",
},
},
}),
],
pages: {
signIn: "/sign-in",
},
callbacks: {
async session({ session, token }) {
if (session.user && token.sub) {
session.user.id = token.sub;
if (token.isSubscribed !== undefined) {
session.user.isSubscribed = Boolean(token.isSubscribed);
}
if (token.email) session.user.email = token.email as string;
if (token.name) session.user.name = token.name as string;
if (token.picture) session.user.image = token.picture as string;
}
return session;
},
async jwt({ token, account, profile }) {
if (account && profile) {
const { getOrCreateUserByEmail } = await import("@/server/services/user");
const dbUser = await getOrCreateUserByEmail(
profile.email!,
profile.name
);
token.sub = dbUser.id;
token.email = profile.email;
token.name = profile.name;
token.picture = (profile as any).picture || profile.image;
token.isSubscribed = dbUser.isSubscribed ?? false;
}
return token;
},
},
session: {
strategy: "jwt",
},
debug: process.env.NODE_ENV === "development",
});