Running getServerSideProps auth checks from external function call
Hello there, I have frequent auth checks in my t3 (pages router), Depending on certain permissions or data, the user will be redirected to other pages. This is the case for multiple pages.
I just want to clarify if offloading the processing on an external function call (to make these function calls callable in other pages more organized and reusable, as well as to declutter the long and repetitive
getServerSideProps
) is recommended or are there certain security risks from offloading the function calls externally? I assume the auth checks would still be done server-side (i plan on putting them somewhere like ~/server/helpers/auth.ts
)6 Replies
I am currently using this approach, i think it's a good way around it?
not sure how to properly type it though, the below works though
you could handle it at the edge (middleware) if you are doing light checks
using GetServerSideProps should work but it's slower for light checks
Unfortunately, I am self-hosting this app via docker, so edge is not available
oh buddy....
middleware runs on the edge runtime either way
lmao
if you aren't doing any server side loading
you can just export it like that
really? was not aware of that, mb mb.. i thought it was vercel-specific
welcome to nextjs
š
something like this?