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