mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-02 22:17:11 +01:00
add mongo adapter via mongoose
This commit is contained in:
@@ -3,11 +3,11 @@ import BookingModel, { Booking, BookingDocument } from './booking'
|
||||
import BillModel, { Bill } from './bill'
|
||||
import { BOOKING_STATUS } from './enums'
|
||||
|
||||
let connectedPromise: Promise<typeof mongoose>
|
||||
let connectedPromise: Promise<mongoose.Mongoose>
|
||||
|
||||
function connect(): Promise<typeof mongoose> {
|
||||
export function connect(): Promise<mongoose.Mongoose> {
|
||||
if (connectedPromise) {
|
||||
return
|
||||
return connectedPromise
|
||||
}
|
||||
|
||||
connectedPromise = mongoose.connect(process.env.MONGO_URI, {
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import NextAuth from "next-auth"
|
||||
import GithubProvider from "next-auth/providers/github"
|
||||
import EmailProvider from "next-auth/providers/email"
|
||||
|
||||
export default NextAuth({
|
||||
providers: [
|
||||
EmailProvider({
|
||||
server: {
|
||||
host: "smtp.sendgrid.net",
|
||||
port: 587,
|
||||
auth: {
|
||||
user: "apikey",
|
||||
pass: process.env.SENDGRID_API_KEY,
|
||||
import { MongoDBAdapter } from "@next-auth/mongodb-adapter"
|
||||
import { connect } from "../../../db"
|
||||
import { Mongoose } from 'mongoose';
|
||||
|
||||
let mongooseConnection: Mongoose;
|
||||
|
||||
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
|
||||
return await NextAuth(req, res, {
|
||||
adapter: MongoDBAdapter({ db: (await connect()).connection.db }),
|
||||
providers: [
|
||||
EmailProvider({
|
||||
server: {
|
||||
host: "smtp.sendgrid.net",
|
||||
port: 587,
|
||||
auth: {
|
||||
user: "apikey",
|
||||
pass: process.env.SENDGRID_API_KEY,
|
||||
},
|
||||
},
|
||||
},
|
||||
from: process.env.FROM_EMAIL
|
||||
}),
|
||||
GithubProvider({
|
||||
clientId: process.env.GITHUB_ID,
|
||||
clientSecret: process.env.GITHUB_SECRET,
|
||||
}),
|
||||
],
|
||||
})
|
||||
from: process.env.FROM_EMAIL
|
||||
}),
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user