0.2.0 • Published 2 years ago

next-auth-mongoose v0.2.0

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

Mongoose with Next Auth v4

How to Use:

  1. Install Package: npm i next-auth-mongoose OR yarn add next-auth-mongoose

  2. 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),
});
  1. 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

0.2.0

2 years ago

0.1.0

2 years ago