-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathauth.ts
60 lines (56 loc) · 1.77 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
53
54
55
56
57
58
59
60
import { NextAuthOptions } from 'next-auth'
import GoogleProvider from 'next-auth/providers/google'
import CredentialsProvider from 'next-auth/providers/credentials'
import { adminAuth, adminDB } from './firebase-admin'
import { FirestoreAdapter } from '@auth/firebase-adapter'
// @ts-ignore
export const authOptions: NextAuthOptions = {
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
}),
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text', placeholder: 'johndoe' },
password: { label: 'Password', type: 'password' },
},
async authorize(credentials) {
const user = {
id: 'demo_user_id',
name: 'John Doe',
email: '[email protected]',
image:
'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=72&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8dXNlciUyMHByb2ZpbGV8ZW58MHx8MHx8fDA%3D',
}
if (credentials?.password === process.env.DEMO_USER_PASSWORD)
return user
else return null
},
}),
],
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',
},
// @ts-ignore
adapter: FirestoreAdapter(adminDB),
} satisfies NextAuthOptions