Make sure you have completed the Supabase setup before continuing with the section

Authentication in sveltepack

Out of the box, sveltepack has traditional email/password authentication for users

Protecting Routes

In an effort to preserve simplicity, client side authentication is used. As a result, route protection will occur on the client side and should be paired with RLS policies to prevent sensitive data from getting into the wrong hands.

With that, there is a handy route protection function in your $lib called protectedRoute. It can be imported to any page or layout using the following line:

import { protectedRoute } from '$lib';

And you can use it by wrapping it in an onMount function within your page or layout.

onMount(async () => {
    protectedRoute()
})

The function will redirect unauthenticated users to the login page.

Data fetching may still occur before user is redirected, so be sure to use RLS on your tables. The Database section will cover this in more detail.

Third-Party Authentication Providers

Supabase offers several authentication methods and providers. An in depth guide for each one can be found here.