-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.ts
More file actions
42 lines (36 loc) · 1001 Bytes
/
auth.ts
File metadata and controls
42 lines (36 loc) · 1001 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
38
39
40
41
42
// named imports
import { NextAuthOptions } from 'next-auth'
import { FirestoreAdapter } from '@auth/firebase-adapter'
import { adminAuth, adminDb } from './firebase-admin'
// default imports
import GoogleProvider from 'next-auth/providers/google'
export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!
})
],
callbacks: {
session: async ({ session, token }) => {
if (session?.user) {
if (token.sub) {
session.user.id = token.sub
const firebaseToken = await adminAuth.createCustomToken(token.sub)
session.firebaseToken = firebaseToken
}
}
return session
},
jwt: async ({ user, token }) => {
if (user) {
token.sub = user.id
}
return token
}
},
session: {
strategy: 'jwt',
},
adapter: FirestoreAdapter(adminDb)
} satisfies NextAuthOptions