ERROR [Better Auth]: State not found undefined

Hello I am trying to implement google sign in.

This is my auth

export const auth = betterAuth({
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID!,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
        }
    },
    database: new Pool({
        connectionString: process.env.BETTER_AUTH_DB_URL!
    }),
    baseURL: "http://localhost:3000",
    basePath: "/auth"
})


This is my client

export const authClient = createAuthClient({
    baseURL: "http://localhost:3000"
    basePath: "/auth"
})


This is how I sign in:

    async signInWithGoogle() {
        console.log('signing in with google')
        const data = await authClient.signIn.social({
            provider: "google"
        })
    }


It works to the point of sending me to google and letting me choose to continue.
But then when it comes back to the app, I see

⚠️
Better Auth Error
We encountered an issue while processing your request. Please try again or contact the application owner if the problem persists.

Return to Application
Error Code: Unknown

And in the server console I see:

ERROR [Better Auth]: State not found undefined

What could be the cause?

By the way I am using my custom server side framework, but have implemented the integration by following how the fastify example does it.
Solution
I figured it out. In the step of re-constructing the URL I forgot to include the query string.
Was this page helpful?