Is there a secure way to redirect users back to a protect route page after they have successfully logged in, instead of just sending back to the home index page?
@michaeltansg there are a number of ways to achieve it. You can store something in a cookie or the session to read after a login in and redirect to that. The flow would look something like:
- Custom redirect middleware saves the intended URL to a cookie or the session
- After login, see if something has been stored
- If so, ‘unsave the value’ and redirect to that, otherwise redirect to the homepage
Since it’s all done by redirects, if you redirect to a protected route, it will still be protected
2 Likes