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