42 lines
1.0 KiB
JavaScript
42 lines
1.0 KiB
JavaScript
import NextAuth from 'next-auth'
|
|
import Providers from 'next-auth/providers'
|
|
import axios from 'axios'
|
|
|
|
const options = {
|
|
providers: [
|
|
Providers.Credentials({
|
|
name: 'Credentials',
|
|
credentials: {
|
|
username: {label: 'Email', type: 'email', placeholder: 'email@exemple.net'},
|
|
password: {label: 'Password', type: 'password'}
|
|
},
|
|
authorize: async credentials => {
|
|
try {
|
|
const user = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/auth/local`, {
|
|
identifier: credentials.username,
|
|
password: credentials.password
|
|
})
|
|
if (user.data) {
|
|
return user.data
|
|
}
|
|
|
|
return null
|
|
} catch (error) {
|
|
const errorMessage = error.response.data.message[0].messages[0].message
|
|
throw new Error(errorMessage)
|
|
}
|
|
}
|
|
})
|
|
],
|
|
session: {
|
|
jwt: true
|
|
},
|
|
pages: {
|
|
signIn: '/soumet',
|
|
error: '/soumet'
|
|
}
|
|
}
|
|
const Auth = (request, response) =>
|
|
NextAuth(request, response, options)
|
|
export default Auth
|