Course lesson

Implement Protected Routes for Authenticated Users with Supabase Auth

Since Supabase requires our user to be authenticated to fetch tweets, it doesn't make sense for an unauthenticated user to visit the landing page. In this lesson, we implement protected routes that are only accessible to authenticated users.

Duration
2 min
Access
Free
Transcript
Retained from source evidence

Since Supabase requires our user to be authenticated to fetch tweets, it doesn't make sense for an unauthenticated user to visit the landing page. In this lesson, we implement protected routes that are only accessible to authenticated users.

Additionally, we create a /login route to redirect unauthenticated users, which allows them to sign in with GitHub.

Code Snippets

Redirect unauthenticated users

const {
  data: { session },
} = await supabase.auth.getSession();

if (!session) {
  redirect("/login");
}

Resources