-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth.ts
44 lines (42 loc) · 1017 Bytes
/
auth.ts
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
import NextAuth from "next-auth";
import Google from "next-auth/providers/google";
declare module "next-auth" {
interface User {
idToken?: string;
}
interface Session {
idToken?: string | undefined;
}
}
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",
scope: "openid profile email",
},
},
}),
],
secret: process.env.NEXTAUTH_SECRET || process.env.AUTH_SECRET, // Try both secrets as fallback
trustHost: true,
session: {
strategy: "jwt",
},
callbacks: {
async jwt({ token, account }) {
if (account) {
token.idToken = account.id_token;
}
return token;
},
async session({ session, token }) {
session.idToken = token.idToken as string;
return session;
},
},
});