mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 22:47:15 +01:00
39 lines
948 B
TypeScript
39 lines
948 B
TypeScript
import { NextApiRequest, NextApiResponse } from 'next'
|
|
import NextAuth from 'next-auth'
|
|
import EmailProvider from 'next-auth/providers/email'
|
|
|
|
import { MongoDBAdapter } from '@next-auth/mongodb-adapter'
|
|
import { MONGO_URI } from '../../../db'
|
|
import { MongoClient } from 'mongodb'
|
|
|
|
let client: MongoClient
|
|
|
|
async function getMongoClient() {
|
|
if (!client) {
|
|
client = new MongoClient(MONGO_URI)
|
|
await client.connect()
|
|
}
|
|
|
|
return client
|
|
}
|
|
|
|
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
|
|
return await NextAuth(req, res, {
|
|
secret: process.env.NEXTAUTH_SECRET,
|
|
adapter: MongoDBAdapter(getMongoClient()),
|
|
providers: [
|
|
EmailProvider({
|
|
server: {
|
|
host: 'smtp.sendgrid.net',
|
|
port: 587,
|
|
auth: {
|
|
user: 'apikey',
|
|
pass: process.env.SENDGRID_API_KEY,
|
|
},
|
|
},
|
|
from: process.env.FROM_EMAIL,
|
|
}),
|
|
],
|
|
})
|
|
}
|