Redirect Component
This component handles the redirect step after a user signs in with an OAuth provider (e.g. Google/Supabase). It is used on pages/signin.astro, extracts login tokens from the URL, calls your server to create a secure session cookie, and then redirects the user to their dashboard (or another page). It works in conjunction with pages/api/auth/set-session.ts - set-session.ts dictates where each user type is redirected after login
How it works
- Page loads → the component checks the URL for
#access_token
and#refresh_token
. - If tokens exist → it sends them to your API route (
/api/auth/set-session
). - The server sets a cookie → meaning the browser is now securely signed in.
- If successful → the user is redirected to
/dashboard
(or another page returned by the server). - If failed → an error message is shown.
When to use
- Place this component on the page your OAuth provider redirects back to.
- Example: if Google login sends the user to
/auth/callback
, add this component there. - It will automatically handle sign-in and send the user to the right place.