MongoDB with NextJS setup problems.

import { betterAuth } from 'better-auth';
import { MongoClient } from 'mongodb';
import { mongodbAdapter } from 'better-auth/adapters/mongodb';
import { magicLink } from 'better-auth/plugins';
import { nextCookies } from 'better-auth/next-js';

const client = new MongoClient(process.env.DB_URI!);
const db = client.db();

export const auth = betterAuth({
    database: mongodbAdapter(db),
    secret: process.env.BETTER_AUTH_SECRET!,

    // Plugins
    plugins: [
        magicLink({
            sendMagicLink: async ({ email, token, url }, request) => {
                // ! Todo: Send the magic link to the user's email
            },
        }),

        // Next.js Cookies
        nextCookies(),
    ],

    // Login Options
    socialProviders: {
        google: {
            clientId: process.env.AUTH_GOOGLE_ID!,
            clientSecret: process.env.AUTH_GOOGLE_SECRET!,
        },
        discord: {
            clientId: process.env.AUTH_DISCORD_ID!,
            clientSecret: process.env.AUTH_DISCORD_SECRET!,
        },
        patreon: {
            clientId: process.env.AUTH_PATREON_ID!,
            clientSecret: process.env.AUTH_PATREON_SECRET!,
        },
    },
});


Heres my auth.ts, and i'm using the standard client instance code.

I'm trying to get a basic login and out loop, but I get this error.
image.png
Was this page helpful?