forked from xplanx/chat-bot-sub-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
64 lines (62 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
61
62
63
64
import NextAuth from 'next-auth'
import GitHub from 'next-auth/providers/github'
import CredentialsProvider from 'next-auth/providers/credentials'
// We default to using GitHub for authentication for local development and production.
// On Preview deployments, we use a dummy credentials provider. This allows folks to easily
// test the app without having to create a custom GitHub OAuth app or change the callback URL
// just to test the application on previews.
// We have a custom /sign-in page for non-preview environments. In preview environments, the user
// will be redirected to /api/auth/signin instead.
export const {
handlers: { GET, POST },
auth,
CSRF_experimental
// @ts-ignore
} = NextAuth({
// @ts-ignore
providers: [
process.env.VERCEL_ENV === 'preview'
? CredentialsProvider({
name: 'Credentials',
credentials: {
username: {
label: 'Username',
type: 'text',
placeholder: 'jsmith'
},
password: { label: 'Password', type: 'password' }
},
async authorize(credentials) {
return {
id: 1,
name: 'J Smith',
email: 'jsmith@example.com',
picture: 'https://i.pravatar.cc/150?u=jsmith@example.com'
} as any
}
})
: GitHub
],
callbacks: {
// @ts-ignore
jwt: async ({ token, profile }) => {
if (profile?.id) {
token.id = profile.id
token.image = profile.picture
}
return token
},
// @ts-ignore
authorized({ auth }) {
return !!auth?.user
},
trustHost: true
},
...(process.env.VERCEL_ENV === 'preview'
? {}
: {
pages: {
signIn: '/sign-in'
}
})
})