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
sommeeer7mo ago
@julius you know what it can be?
cje
cje7mo 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
Josh7mo ago
Somewhere somehow you are indirectly importing your Prisma client to your front end and next is stopping you from doing so
sommeeer
sommeeer7mo 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
Josh7mo ago
Found it
sommeeer
sommeeer7mo 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
Josh7mo ago
You're importing uploads3 from your helpers file, which also contains multiple indirect imports of prisma
sommeeer
sommeeer7mo ago
oh
Josh
Josh7mo ago
Separate out your helper files so that one is backend helpers and one is front end
sommeeer
sommeeer7mo ago
guess its my fault then
Josh
Josh7mo ago
Yep
sommeeer
sommeeer7mo 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