-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.ts
39 lines (37 loc) · 1.15 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
import NextAuth from 'next-auth'
import { NextAuthConfig } from 'next-auth'
import CredentialsProvider from 'next-auth/providers/credentials'
export const authConfig: NextAuthConfig = {
providers: [
CredentialsProvider({
name: 'Credentials',
credentials: {
username: { label: 'Username', type: 'text', placeholder: 'raicds' },
password: { label: 'Password', type: 'password' },
csrf_token: { label: 'Token', type: 'hidden' },
},
async authorize(credentials) {
// This is where you would typically check the user credentials against your database
if (credentials?.username === 'user' && credentials?.password === 'password') {
return { id: '1', name: 'R Siqueira', email: 'me@raisiqueira.io' }
}
return null
},
}),
],
callbacks: {
async jwt({ token, user }) {
if (user) {
token.id = user.id
}
return token
},
async session({ session, token }) {
if (session.user) {
session.user.id = token.id as string
}
return session
},
},
}
export const { handlers, auth, signIn, signOut } = NextAuth(authConfig)