Hi, how do I redirect my page to login page in a backend route protected by verify_session. I am using Flask and Plain JS frontend. So if a user navigates to domain.com/account , if session is not valid, I'd want to redirect to /login . Right now, I just get a "{"message":"unauthorised"}" with 401 response.
r
rp_st
09/21/2022, 11:52 AM
hey! you would do check if the status code is 401 from the response, and if it is, would do
window.location.href = "/login"
(or using whatever router that you use)
h
hermit908
09/21/2022, 12:04 PM
Hi, I was wondering if I could return a 302 redirect from the backend itself if verify_session fails in Flask
r
rp_st
09/21/2022, 12:05 PM
hmm. You could. Instead of using verify_session middleware, you can use the get_session function directly, and then catch the unauthoriused error from that and return a 302
SuperTokens is an open source authentication solution offering features like: Different types of login: Email / password, Passwordless (OTP or Magic link based).