forked from djyde/cusdis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.server.ts
72 lines (67 loc) · 1.7 KB
/
config.server.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
72
import Providers, { AppProviders } from 'next-auth/providers'
import { prisma, resolvedConfig } from './utils.server'
/**
* Auth Providers
* https://next-auth.js.org/configuration/providers
*/
const providers: AppProviders = []
if (resolvedConfig.useLocalAuth) {
providers.push(
Providers.Credentials({
name: 'Userename',
credentials: {
username: {
label: 'Username',
type: 'text',
placeholder: 'env: USERNAME',
},
password: {
label: 'Password',
type: 'password',
placeholder: 'env: PASSWORD',
},
},
async authorize(credentials: { username: string; password: string }) {
if (
credentials.username === process.env.USERNAME &&
credentials.password === process.env.PASSWORD
) {
const user = await prisma.user.upsert({
where: {
id: credentials.username,
},
create: {
id: credentials.username,
name: credentials.username,
},
update: {
id: credentials.username,
name: credentials.username,
},
})
return user
} else {
return null
}
},
}),
)
}
if (resolvedConfig.useGithub) {
providers.push(
Providers.GitHub({
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET,
scope: 'read:user,user:email',
}),
)
}
if (resolvedConfig.google.id) {
providers.push(
Providers.Google({
clientId: resolvedConfig.google.id,
clientSecret: resolvedConfig.google.secret,
}),
)
}
export const authProviders = providers