SvelteKit + Supabase Starter Template

๐Ÿš€ Ready-to-use features:
  • Authentication: Login/logout with Supabase Auth
  • Protected Routes: Server-side auth checks with redirects
  • Database Utils: Development tools for DB operations
  • Bootstrap UI: Responsive design out of the box
  • Cloudflare Ready: Configured for Cloudflare Pages deployment
๐Ÿ”— Test Navigation

Not Auth: Public page accessible to everyone

Auth Require: Protected page - redirects to login if not authenticated

DB Utils: Database utilities for development (secure before production)

๐Ÿ” Adding Authentication to New Pages

Option 1: Auto-redirect to login Simpler

// +page.server.ts
import { requireAuthWithRedirect } from '$lib/server/auth';

export const load = async (event) => {
  const user = await requireAuthWithRedirect(event);
  return { user };
};

โœ… No conditional logic needed in +page.svelte - user is always authenticated when page renders

Option 2: Show login message More flexible

// +page.server.ts
import { checkAuth } from '$lib/server/auth';

export const load = async (event) => {
  const user = await checkAuth(event);
  return { user };
};

// +page.svelte - REQUIRED conditional logic
{#if !data.user}
  <div class="alert alert-warning">
    Please <a href="/login?redirectTo={$page.url.pathname}">login</a>
  </div>
{:else}
  <!-- Your protected content -->
{/if}

โš ๏ธ Must add conditional logic to +page.svelte to handle unauthenticated users

โš™๏ธ Environment Setup

Required environment variables in .env:

PUBLIC_SUPABASE_URL=your_supabase_url
PUBLIC_SUPABASE_ANON_KEY=your_anon_key
SUPABASE_SERVICE_ROLE=your_service_role_key
๐Ÿงช Sample Components
Reactivity Example

Count: 0

Client Side

Hello World!

Server Side

Check terminal for output

ยฉ 2025 Fabian Manzano