Unable to have a environment variable only on client?
I'm configuring the
better-auth
library for my app and it requires the BETTER_AUTH_URL
environment variable on the client side, therefore I prefixed it as NEXT_PUBLIC_BETTER_AUTH_URL
.
However, this causes an runtime error:
How do I fix this?Solution:Jump to solution
what if you try having two env with the same value?
BETTER_AUTH_URL
on server and NEXT_PUBLIC_BETTER_AUTH_URL
on client9 Replies
Attempting to add the environment variable to the server errors, saying that
NEXT_PUBLIC_
-prefixed variables shouldn't be added to the server config
A similar error occurs if I instead remove the
NEXT_PUBLIC_
prefix from the client config
Solution
what if you try having two env with the same value?
BETTER_AUTH_URL
on server and NEXT_PUBLIC_BETTER_AUTH_URL
on clientlooks like they'll handle both

Your next_public env belong into client:{} object inside of createEnv() as described here:
https://github.com/t3-oss/t3-env
GitHub
GitHub - t3-oss/t3-env
Contribute to t3-oss/t3-env development by creating an account on GitHub.
that worked for me but i was wondering if there was a way to not use 2 env with the same value
i haven't used t3-env but i think what you want to do is something like this?

Env
Never build your apps with invalid environment variables again. Validate and transform your environment with the full power of Zod.
seems close enough, but i can't seem to understand what the docs are telling me to do once i have the two different schemas