Better Auth + Vercel Preview Deployements + Nuxt 3
Hi @bekacru spoke to you on X. You said i should tag you.
this is my auth which is in /server/utils/auth
and the below is my auth client in lib in root
the below is the error i get in vercel preview deployemnts
i dont get it in production since i set betterauthurl env var for prod domain.
This has made it almost impossible to use better auth
15 Replies
i did also try to get baseUrl based on availble env vars but i get the same error. The funciton i used
the base url need to be passed to the authClient
Ok. Just confirming. Not on the server. Just client?
For vercel preview deployments to work.
Yeah on the client
Ok. Will try now. Thanks so much.
no doesnt work even on dev now @bekacru
all useSession dont work now with this
It is a nuxt ssr
are you calling
useSession
with useFetch
for ssr?Tried both. Generally have been using usefetch. Tried to just use directly also to test. Neither work.
what is the error message?
same as before?
Nope. Now all session are not set.
Also give me type error when I add base url to auth client.
Haven’t been able to push as can’t get into any page with baseurl set even in dev.
Before dev worked fine.
Since have better auth url set as env
In dev and production. Now it just shows a 500 error……
it's hard to tell what is the issue one other thing you can try on next is do something like this instead
still get this when depolyed
and set like this
this will never work it isnt in a plugin or composable doesnt have nuxt context availble it is just in libs folder in main dir
for the record it's
baseURL
not baseUrl
also im not super familiar with nuxt, the issue in general is it can't infer the base url. By default, without you defining the baseURL, it should be able to infer it.
one thing I'd try remove the baseURL and don't pass any getBaseURL
or anything for the client or the server and just let it infer itself.
also check this resources
https://github.com/leamsigc/nuxt-better-auth-drizzle
https://github.com/atinux/nuxthub-better-authGitHub
GitHub - leamsigc/nuxt-better-auth-drizzle: Nuxt 4 Integration with...
Nuxt 4 Integration with Better auth and Drizzle ORM - leamsigc/nuxt-better-auth-drizzle
GitHub
GitHub - atinux/nuxthub-better-auth: A demo of using Better Auth wi...
A demo of using Better Auth with Nuxt & NuxtHub (Cloudflare D1 & KV). - atinux/nuxthub-better-auth
been through both of those! infer doesnt work with nothing set tried. atinux has got alot of custom things from his auth in - which isnt what i am looking for and other one obviously wont work in this situation since it is not addressed there at all
thanks for your help! really want this to work! will pg post after a working demo if we can get this up!
set NEXT_PUBLIC_SITE_URL to your production URL but only for production environment on Vercel
Do not set NEXT_PUBLIC_SITE_URL for any other environments
It will use NEXT_PUBLIC_VERCEL_URL for previews
And in dev mode it falls back to localhost:3000
Oh this is for NEXT idk about NUXT env
Here is the port for NUXT
use BETTER_AUTH_URL instead of SITE_URL if you have that set for production
But make sure BETTER_AUTH_URL is only set on production environment, nowhere else
Solved. Thanks a lot.
Yip it was. Not so clear what issue was.
Think most likely combination between only testing vercel url without the https and misspelling baseURL alternating!