-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
35 lines (35 loc) · 1008 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
import { NextAuthOptions } from "next-auth";
import { FirestoreAdapter } from "@auth/firebase-adapter";
import GoogleProvider from "next-auth/providers/google";
import { adminAuth, adminDb } from "./firebase-admin";
export const authOptions: NextAuthOptions = {
secret: process.env.NEXTAUTH_SECRET,
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;