0

User data isn't saving to mongo, I did this a while ago but I can't seem to get it to work now. I'm using "mongodb": "^3.5.9" so it's not a version error and I can also connect to the database outside of NextAuth, so it's not a connection issue from what I can see.

[...nextauth].js

import NextAuth from "next-auth"
import GoogleProvider from "next-auth/providers/google"

export default NextAuth({
    providers: [
        GoogleProvider({
            clientId: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET
        })
    ],
    jwt: {
        secret: process.env.JWT_SECRET,
    },
    database: process.env.DATABASE_URL,
})

.env

GOOGLE_CLIENT_ID = 
GOOGLE_CLIENT_SECRET = 

NEXTAUTH_URL = http://localhost:3000

JWT_SECRET = 

DATABASE_URL = mongodb+srv://username:password@cluster0.klwliur.mongodb.net/?retryWrites=true&w=majority
  • 2
    You have to use NextAuth MongoDB adapter to make this work. Here is the link to the doc https://next-auth.js.org/adapters/mongodb – Kiran k Sep 23 '22 at 04:31

0 Answers0