Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
-
If on each 401 I could do something like this: Line 284 in b3ffe50 then next-auth could trust me there is no session without doing extra requests. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, could you please advice if there is some performance/resources consumption drawback in the approach below:
(I am using jwt sessions with mongo on vercel)
I just check if user is authorized on corresponding API on back end using 'getSession' and if not - return 401 so on client side if I see 401 instead of expected data - I show message/link to login.
So my question is - am I causing excessive requests to back end?
Maybe by using 'useSession' on client side next-auth will ping server only few times and then just cache session/info session is missing in browser instead of doing requests to backend on each data request?
Or it's not a big difference and I can stay with my API-based approach and enjoy a bit more readable and reusable code?
Statistically normal user will not lurk over random private URLs trying to load them multiple times being not authorized, right?
Reason why I want to not check session separately - to not worry about it at all, so from react perspective there is no separate phases with waiting for loading session info / checking session /waiting for loading data . Everything is hidden into single loading data phase (handled by SWR) and auth error is just one of possible data errors. So in UI I don't worry explicitly which page is restricted and which is available anonymously, all this is up to back-end and generic error handler.
Beta Was this translation helpful? Give feedback.
All reactions