-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.ts
92 lines (82 loc) · 2.48 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// import { CredentialsProvider } from 'next-auth/providers/';
// import { GitHubProvider } from 'next-auth/providers/github';
import NextAuth from 'next-auth';
import GoogleProvider from 'next-auth/providers/google';
import GitHubProvider from 'next-auth/providers/github';
import CredentialsProvider from 'next-auth/providers/credentials';
const credentialsConfig = CredentialsProvider({
name: 'Credentials',
credentials: {
username: {
label: 'User Name',
},
password: {
label: 'Password',
type: 'password',
},
},
async authorize(credentials) {
if (credentials.username === 'cc' && credentials.password === '123') {
return {
name: 'Chris Catto',
};
} else return null;
},
});
const config = {
providers: [
GoogleProvider({
clientId: process.env.AUTH_GOOGLE_ID,
clientSecret: process.env.AUTH_GOOGLE_SECRET,
}),
GitHubProvider({
clientId: process.env.AUTH_GITHUB_ID,
clientSecret: process.env.AUTH_GITHUB_SECRET,
}),
credentialsConfig,
],
// this callback section is used for Middleware protect sections but need to resolve some typescript type errors yeah!
// callbacks: {
// authorized({ request, auth }){
// const { pathname } = request.nextUrl;
// if(pathname === "/auth-protected-middleware") return !!auth;
// return true
// }
// }
};
export const {
handlers: { GET, POST },
auth,
signIn,
signOut,
} = NextAuth(config);
// old working:
// export const { handlers: { GET, POST}, auth, signIn, signOut } = NextAuth({
// providers: [
// GoogleProvider({
// clientId: process.env.AUTH_GOOGLE_ID,
// clientSecret: process.env.AUTH_GOOGLE_SECRET,
// }),
// GitHubProvider({
// clientId: process.env.AUTH_GITHUB_ID,
// clientSecret: process.env.AUTH_GITHUB_SECRET,
// }),
// ]
// })
// #TODO could move this to /lib folder or /actions folder
// import { SignupFormSchema, FormState } from '@/app/lib/definitions'
// export async function signup(state: FormState, formData) {
// // Validate form fields
// const validatedFields = SignupFormSchema.safeParse({
// name: formData.get('name'),
// email: formData.get('email'),
// password: formData.get('password'),
// })
// // If any form fields are invalid, return early
// if (!validatedFields.success) {
// return {
// errors: validatedFields.error.flatten().fieldErrors,
// }
// }
// // Call the provider or db to create a user...
// }