-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauth.ts
71 lines (67 loc) · 1.98 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
61
62
63
64
65
66
67
68
69
70
71
export const runtime = 'edge'
import NextAuth, { type DefaultSession } from 'next-auth'
import GitHub from 'next-auth/providers/github'
import GoogleProvider from "next-auth/providers/google"
import type { Adapter } from 'next-auth/adapters'
import { SupabaseAdapter } from "@auth/supabase-adapter"
declare module 'next-auth' {
interface Session {
user: {
/** The user's id. */
id: string,
plan: string,
created_at: number,
} & DefaultSession['user']
}
}
export const {
handlers: { GET, POST },
auth
} = NextAuth({
providers: [
GitHub({
allowDangerousEmailAccountLinking: true
}),
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
allowDangerousEmailAccountLinking: true
})
],
adapter: process.env.NODE_ENV === 'production' ? SupabaseAdapter({
url: process.env.NEXT_PUBLIC_SUPABASE_URL as string,
secret: process.env.SUPABASE_SERVICE_ROLE_KEY as string,
}) as Adapter : undefined,
//@ts-ignore
callbacks: {
jwt({ token, profile }) {
if (profile) {
token.id = profile.id
token.image = profile.avatar_url || profile.picture
}
return token
},
session: ({ session, token, user }) => {
if (session?.user && token?.sub) {
session.user.id = process.env.NODE_ENV === 'production' ? String(token.sub) : process.env.MOCK_USERID as string
}
console.log('auth => ', user)
return session
},
authorized({ auth }) {
return !!auth?.user
},
async signIn({ user, account, profile, email, credentials }) {
const isAllowedToSignIn = true
console.log('email', user, email)
return isAllowedToSignIn
},
redirect: async (params: { url: string; baseUrl: string; }) => {
return Promise.resolve(params.url)
}
},
pages: {
signIn: '/login', // overrides the next-auth default signin page https://authjs.dev/guides/basics/pages
error: '/apply',
}
})