mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
41 lines
988 B
TypeScript
41 lines
988 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, MONGODB_OPTIONS } from "../../../db"
|
|
import { MongoClient } from "mongodb";
|
|
|
|
let client: MongoClient;
|
|
|
|
async function getMongoClient() {
|
|
if (!client) {
|
|
client = new MongoClient(MONGO_URI, MONGODB_OPTIONS);
|
|
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
|
|
}),
|
|
],
|
|
})
|
|
}
|
|
|
|
|