#Better Auth with Convex working in dev but broken in prod

13 messages · Page 1 of 1 (latest)

next nexus
#

I am trying to get authentication to work with my convex + better auth set up. I've got the following envs in my dev and production deployments in Convex:
BETTER_AUTH_SECRET, SITE_URL. In development, everything works fine however in production I am unable to login or sign up. I am able to create an account but in production it gives me this error:

Error

Uncaught Error: Unauthenticated
    at getAuthUser [as getAuthUser] (../../node_modules/@convex-dev/better-auth/src/client/index.ts:538:13)
    at async handler (../../convex/auth.ts:44:9)

My getCurrentUser method looks like this:

export const getCurrentUser = query({
    args: {},
    handler: async (ctx) => {
        const user = await authComponent.getAuthUser(ctx);
        return {
            ...user,
            userProfiles: await ctx.db
                .query('userProfiles')
                .withIndex('by_userId', (q) => q.eq('userId', user?._id))
                .collect()
        };
    }
});

I would really appreciate some help here I've been trying for hours to resolve this and find out what is causing this because in production it is just not working. It's deployed on vercel

rapid fjordBOT
#

Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.

    - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
    - Use [search.convex.dev](https://search.convex.dev) to search Docs, Stack, and Discord all at once.
    - Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
    - Avoid tagging staff unless specifically instructed.

    Thank you!
lilac bear
#

This a brand new repo you working on?

next nexus
#

Yeah

lilac bear
#

Are you able to share link or send code? need to see full picture as it will be much easier for me to help.

next nexus
#

Yeah let me DM you the repo

lilac bear
#

ty

drifting oak
#

@next nexus i’m almost 100% sure you are just missing the correct env variable with the production url somewhere. either you have a cors issue with the cross domain plugin, or google auth isn’t being given the correct url in the google cloud console settings. lmk

next nexus
next nexus
drifting oak
#

that’s always the other problem lol

#

so hard to troubleshoot