Error: ❌Attempted to access a server-side environment variable on the client - Weird T3 Stack bug
So I am trying to check if a
For example
session.user.role === Role.Admin
in getServerSideProps()
in all the /admin/ routes.
It works well for a lot of the routes, but not on some. Im using the same code to check admin status in all admin routes using getServerSideProps()
.For example
/admin/news
works fine, but when I go to /admin/news/new
i get the error.
This is the repo btw: https://github.com/sommeeeer/migotos
Anyone know what this might be? Seems like a weird t3 stack bug.GitHub
GitHub - sommeeeer/migotos
Contribute to sommeeeer/migotos development by creating an account on GitHub.
Solution:Jump to solution
You're importing uploads3 from your helpers file, which also contains multiple indirect imports of prisma
12 Replies
@julius you know what it can be?
dont ping maintainers for something that is almost certainly on your side
if you believe you have found an actual bug in library code, make a minimal reproduction and open an issue with that
Somewhere somehow you are indirectly importing your Prisma client to your front end and next is stopping you from doing so
yeah
my bad sorry guys
i cant however find anywhere that I am importing Prisma client in my frontend
im using the pages router
its giving me that error even though im running
db
from getServerSideProps()
. The weird thing is that it works fine on some routes. For.example /admin
and /admin/news
but once I go to /admin/news/new
it throws that error. Which is strange, cause im doing the same logicFound it
Would really appreciate if anyone could pinpoint whats wrong, so I dont have to check if a user is admin client-side.
Solution
You're importing uploads3 from your helpers file, which also contains multiple indirect imports of prisma
oh
Separate out your helper files so that one is backend helpers and one is front end
guess its my fault then
Yep
😄
it worked like a charm before
but suddenly today i started having that error
dunno why
it didnt show before
@Josh its working like a charm now. i created a
helpers.ts
inside /src/server/helpers.ts
now for serverside helpers.
thanks a lot