AthletiFi / athletifi-website

Official website for AthletiFi
https://www.athleti.fi
1 stars 5 forks source link

Implement redirect to '/login' when user visits a protected page AND redirect back to the originally visited page after login/register #256

Closed chef-louis closed 1 month ago

chef-louis commented 1 month ago

But if user visited '/login' or '/register', they should be redirected to profile page

chef-louis commented 1 month ago

Refactored the auth group layout.tsx files by adding individual layout.tsx files for each protected path to check for an authenticated user. If there is no authenticated user then the page redirects to the login page with a redirect url parameter which is used by the login page for subsequent redirecting.

chef-louis commented 1 month ago

Dynamic redirect logic via federated sign-in is a bit more tricky as it's not possible to have the OAuth provider add a query parameter for us on the redirect URL. That said, after some quick research it looks like there are 2 viable solutions:

  1. OAuth does allow for a state parameter to be modified and sent back, which we may be able to tweak / leverage conditionally
  2. Store data via cookies to have the browser hold onto where the user should be redirected to when authentication is complete.