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
I thought of using
401
for unauthenticated. and 403
for unauthorized. it seems not a good idea thoughIf 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•3y ago
Message Not Public
Sign In & Join Server To View
whoops. then 302 lol
always forget which is which
Your approach is fine honestly
you can use specific codes but like
just make it work
thanks y'all I appreciate it