Mongodb Adapter Not Working with Tanstack Start #1285

Closed
opened 2026-03-13 08:31:21 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @maharshi365 on GitHub (May 30, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I am trying to setup a mongodb connection in better-auth but redirects arent working from the FE once i click signin.

This is my backend code. DB is setup in a different file with the same steps as the adapter instructions

import { betterAuth } from "better-auth";
import { reactStartCookies } from "better-auth/react-start";
import { mongodbAdapter } from "better-auth/adapters/mongodb";
import { BetterAuthDB } from "../mongo";

export const auth = betterAuth({
    database: mongodbAdapter(BetterAuthDB),
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID as string,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
        },
    },
    emailAndPassword: {
        enabled: true,
    },
    plugins: [
        reactStartCookies()
    ]
})

This is my FE

<Button variant="outline" className="w-full" onClick={() => signIn.social({ provider: 'google' })}>
                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
                    <path
                      d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z"
                      fill="currentColor"
                    />
                  </svg>
                  Login with Google
                </Button>

This is my authclient

import { createAuthClient } from 'better-auth/react';

export const { useSession, signIn, signOut, signUp, getSession } = createAuthClient({
  baseURL: process.env.BETTER_AUTH_URL as string,
});

Current vs. Expected behavior

Right now if i click signin, the page just reloads and on the BE i get a new verification in the database, but I dont get redirected to the google login form. If i comment out the database adapter everything works as expected.

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS: Windows 10
- Browser: Chrome
- TanstackStart: 1.120.10

Which area(s) are affected? (Select all that apply)

Client, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: mongodbAdapter(BetterAuthDB),
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID as string,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
        },
    },
    emailAndPassword: {
        enabled: true,
    },
    plugins: [
        reactStartCookies()
    ]
});

Additional context

No response

Originally created by @maharshi365 on GitHub (May 30, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I am trying to setup a mongodb connection in better-auth but redirects arent working from the FE once i click signin. This is my backend code. DB is setup in a different file with the same steps as the [adapter instructions](https://www.better-auth.com/docs/adapters/mongo) ```TS import { betterAuth } from "better-auth"; import { reactStartCookies } from "better-auth/react-start"; import { mongodbAdapter } from "better-auth/adapters/mongodb"; import { BetterAuthDB } from "../mongo"; export const auth = betterAuth({ database: mongodbAdapter(BetterAuthDB), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, emailAndPassword: { enabled: true, }, plugins: [ reactStartCookies() ] }) ``` This is my FE ```TSX <Button variant="outline" className="w-full" onClick={() => signIn.social({ provider: 'google' })}> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z" fill="currentColor" /> </svg> Login with Google </Button> ``` This is my authclient ```TS import { createAuthClient } from 'better-auth/react'; export const { useSession, signIn, signOut, signUp, getSession } = createAuthClient({ baseURL: process.env.BETTER_AUTH_URL as string, }); ``` ### Current vs. Expected behavior Right now if i click signin, the page just reloads and on the BE i get a new verification in the database, but I dont get redirected to the google login form. If i comment out the database adapter everything works as expected. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS: Windows 10 - Browser: Chrome - TanstackStart: 1.120.10 ``` ### Which area(s) are affected? (Select all that apply) Client, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: mongodbAdapter(BetterAuthDB), socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string, }, }, emailAndPassword: { enabled: true, }, plugins: [ reactStartCookies() ] }); ``` ### Additional context _No response_
Author
Owner

@maharshi365 commented on GitHub (Jun 1, 2025):

Im closing this. Had to use a e.preventDefault() and it worked.

@maharshi365 commented on GitHub (Jun 1, 2025): Im closing this. Had to use a ```e.preventDefault()``` and it worked.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1285