You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
import { NextApiHandler } from "next";
|
|
import NextAuth from "next-auth";
|
|
import Providers from "next-auth/providers";
|
|
import { PrismaAdapter } from '@next-auth/prisma-adapter'
|
|
import GoogleProvider from "next-auth/providers/google";
|
|
import EmailProvider from 'next-auth/providers/email'
|
|
import prisma from '../../../lib/prisma'
|
|
|
|
|
|
const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);
|
|
export default authHandler;
|
|
|
|
const options = {
|
|
providers: [
|
|
GoogleProvider({
|
|
clientId: process.env.GOOGLE_CLIENT_ID,
|
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
|
authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
|
|
}),
|
|
EmailProvider({
|
|
server: {
|
|
host: process.env.EMAIL_SERVER_HOST,
|
|
port: parseInt(process.env.EMAIL_SERVER_PORT),
|
|
auth: {
|
|
user: process.env.EMAIL_SERVER_USER,
|
|
pass: process.env.EMAIL_SERVER_PASSWORD
|
|
}
|
|
},
|
|
from: process.env.EMAIL_FROM
|
|
}),
|
|
],
|
|
adapter: PrismaAdapter(prisma),
|
|
secret: process.env.SECRET,
|
|
callbacks: {
|
|
async session({ session, user }) {
|
|
const getCurrentUser = await prisma.user.findMany({
|
|
where: { email: session.user.email },
|
|
})
|
|
//récupération du role
|
|
const { role } = getCurrentUser[0];
|
|
session.user.role = role
|
|
return session
|
|
}
|
|
},
|
|
pages: {
|
|
signIn: '/mon-compte',
|
|
// signOut: '/auth/signout',
|
|
error: '/auth/error', // Error code passed in query string as ?error=
|
|
verifyRequest: '/verify-request', // (used for check email message)
|
|
// newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)
|
|
}
|
|
}
|