-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
52 lines (48 loc) · 1.22 KB
/
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
45
46
47
48
49
50
51
52
import NextAuth from 'next-auth'
export const tokenIssuer = process.env.AUTH_CLIENT_ISSUER || 'https://oauth.cerberauth.com'
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [{
id: 'cerberauth',
name: 'CerberAuth',
issuer: tokenIssuer,
type: 'oidc',
clientId: process.env.AUTH_CLIENT_ID,
clientSecret: process.env.AUTH_CLIENT_SECRET,
checks: ['pkce', 'state', 'nonce'],
authorization: {
params: { scope: 'openid profile email offline_access' }
},
idToken: true,
}],
session: { strategy: 'jwt' },
callbacks: {
signIn: async ({ account }) => {
if (account?.provider === 'cerberauth') {
return true
}
return false
},
jwt: ({ token, profile }) => {
if (profile?.sub && profile?.email) {
return {
sub: profile.sub,
name: profile.name,
email: profile.email,
picture: profile.picture,
}
}
return token
},
session: async ({ session, token, user }) => {
return {
...session,
user: user ?? {
id: token.sub,
name: token.name,
email: token.email,
image: token.picture,
},
}
},
}
})