0.2.0 • Published 3 years ago
next-auth-mongoose v0.2.0
Mongoose with Next Auth v4
How to Use:
Install Package:
npm i next-auth-mongoose
ORyarn add next-auth-mongoose
pages/api/auth/[...nextauth].ts
:
import NextAuth from "next-auth";
import MongooseAdapter from "next-auth-mongoose";
import connect from "../../../utils/mongoConnect";
const { usersClient } = connect();
export default NextAuth({
secret: process.env.SECRET,
providers: [
// Providers
],
adapter: MongooseAdapter(usersClient),
});
utils/mongoConnect.ts
:
import mongoose from "mongoose";
export default function connect() {
const usersClient = mongoose.createConnection(process.env.MONGO_URI);
// User Model
const User =
mongoose.models.User ||
mongoose.model(
"User",
new mongoose.Schema({
id: {
type: String,
required: true,
},
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
emailVerified: {
type: String,
required: false,
},
image: {
type: String,
required: true,
},
})
);
return { usersClient };
}
Opening An Issue
Please be as descriptive on your issue. This is a small repository so you can expect bugs. Open an issue here: https://github.com/Xzoky174/next-auth-mongoose/issues