Cloud

Users & Auth

Full-featured auth system with email, Google and session management.

Supported methods

  • Email + password (with confirm email)
  • Magic link (passwordless)
  • Google OAuth
  • GitHub OAuth
  • Phone + SMS code

Sign up & sign in

ts
import { supabase } from "@/integrations/supabase/client";

const { error } = await supabase.auth.signUp({
  email,
  password,
  options: {
    emailRedirectTo: `${window.location.origin}/`,
    data: { display_name: fullName },
  },
});

const { error: e2 } = await supabase.auth.signInWithPassword({ email, password });
await supabase.auth.signOut();
Always set emailRedirectTo, otherwise the user will end up on the wrong URL after confirmation.

Current user

ts
import { useAuth } from "@/hooks/useAuth";

const { user, session, loading, signOut } = useAuth();
In the onAuthStateChange callback, never call any other Supabase function synchronously — it will cause a deadlock. Use setTimeout(..., 0).

Roles and permissions

Never store roles in profiles. Use a separate user_roles table with a security definer function.

sql
create type public.app_role as enum ('admin', 'user');

create table public.user_roles (
  id uuid primary key default gen_random_uuid(),
  user_id uuid references auth.users on delete cascade not null,
  role app_role not null,
  unique (user_id, role)
);

create or replace function public.has_role(_user_id uuid, _role app_role)
returns boolean
language sql stable security definer set search_path = public
as $$
  select exists (
    select 1 from public.user_roles
    where user_id = _user_id and role = _role
  )
$$;

Configuration in Cloud

  • OAuth providers (Google, GitHub) — client ID and secret
  • Email templates (confirm, reset, magic link)
  • Site URL and redirect URLs (critical for deploy!)
  • Auto-confirm sign-ups (for development)