Error: ❌Attempted to access a server-side environment variable on the client - Weird T3 Stack bug

So I am trying to check if a 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.
No description
No description
Solution:
You're importing uploads3 from your helpers file, which also contains multiple indirect imports of prisma
Jump to solution
12 Replies
sommeeeR
sommeeeROP13mo ago
@julius you know what it can be?
cje
cje13mo ago
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
Josh
Josh13mo ago
Somewhere somehow you are indirectly importing your Prisma client to your front end and next is stopping you from doing so
sommeeeR
sommeeeROP13mo ago
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 dbfrom 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/newit throws that error. Which is strange, cause im doing the same logic
Josh
Josh13mo ago
Found it
sommeeeR
sommeeeROP13mo ago
Would really appreciate if anyone could pinpoint whats wrong, so I dont have to check if a user is admin client-side.
Solution
Josh
Josh13mo ago
You're importing uploads3 from your helpers file, which also contains multiple indirect imports of prisma
sommeeeR
sommeeeROP13mo ago
oh
Josh
Josh13mo ago
Separate out your helper files so that one is backend helpers and one is front end
sommeeeR
sommeeeROP13mo ago
guess its my fault then
Josh
Josh13mo ago
Yep
sommeeeR
sommeeeROP13mo ago
😄 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.tsnow for serverside helpers. thanks a lot
Want results from more Discord servers?
Add your server