Next.js Discord

Discord Forum

How can I "modify" the mongodb adapter to add custom values? (NextAuth)

Unanswered
Cinnamon posted this in #help-forum
Open in Discord
CinnamonOP
I want to get the Minecraft account (i can do that myself) in the background and then add the uuid to the account’s document in the database, but I don’t know where I should put this function, and how I could implement it

I’m using MongoDB

import AzureADProvider from "next-auth/providers/azure-ad"
import { MongoDBAdapter } from "@auth/mongodb-adapter"
import clientPromise from "@/lib/mongodb"
import NextAuth from "next-auth/next"

export const authOptions = {
  adapter: MongoDBAdapter(clientPromise) as any,
  secret: process.env.NEXTAUTH_SECRET,
  providers: [
    AzureADProvider({
      clientId: process.env.AZURE_AD_CLIENT_ID as string,
      clientSecret: process.env.AZURE_AD_CLIENT_SECRET as string,
      tenantId: process.env.AZURE_AD_TENANT_ID,
      httpOptions: { timeout: 10000 },
      authorization: { params: { scope: "openid offline_access profile email XboxLive.signin Xboxlive.offline_access" } }
    })
  ],
  callbacks: {
    session: async ({ session, token }) => {
      if (session?.user) {
        session.user.id = token.uid;
      }
      return session;
    },
    jwt: async ({ token, user, account }) => {
      if (user) {
        token.uid = user.id;
      }
      console.log(account)
      return token;
    },
  },
  session: {
    strategy: 'jwt',
  },
}
export default NextAuth(authOptions)

async function getMinecraft() {
    // ...do stuff
}


By "adding a value" i mean adding the UUID here:

1 Reply

CinnamonOP
Like this