How to handle a full third-party api, and logout user when respons is 401 redirecting to login.
Unanswered
Sirex woodwasp posted this in #help-forum
Sirex woodwaspOP
How can i validade status response on every request to the third-party api?
I'm using Authjs with credentials
I'm using Authjs with credentials
6 Replies
Sun bear
You are doing something wrong if you are allowing user to call api without being logged in in the first place. There is no reason to logout user if response is 401. Code 401 means the user is not authorized to view the page which means that the api did not return any critical information. If anything you should prompt the user to login and not sign out them...
Sirex woodwaspOP
the user must sign in to access the app, but the token expires in 8 hours, so i want to sign user out and redirect to login
Sun bear
user is automatically signed out if the auth cookie expires. so you can just make a check if the user exists (depending on what auth provider you are using) and show the login page accordingly
Sirex woodwaspOP
i have this "global fetch", all request pass throug this, what should i do to signout the user and redirect to /auth/signin?
this is not working
Spectacled bear
you're using an hook in a server function... remove router and do Response.redirect to /auth/login