what is the best way to redirect the user to login page in CSR?

I have this jamstack app and I want to redirect unauthenticated user to the login page, in case the session expired he still have the code in the browser to do certain actions. but the cookie is not there. so in the server I only send a response with 200 status. that says {redirect: true}. and I act in the front based on that. is this a good way to do it? or is there a more standard way?
6 Replies
venego
venegoOP3y ago
I thought of using 401 for unauthenticated. and 403 for unauthorized. it seems not a good idea though
dan
dan3y ago
If the user is unauthenticated then use the 401 http status. if you’re redirecting them on the server use 301 (temp redirect). if you’re redirecting on the client i’d use 401 and have the client redirect to login
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
dan
dan3y ago
whoops. then 302 lol always forget which is which
zenith
zenith3y ago
Your approach is fine honestly you can use specific codes but like just make it work
venego
venegoOP3y ago
thanks y'all I appreciate it
Want results from more Discord servers?
Add your server