Supabase Auth, JWT and secret key guides
Sign-up triggers, email links, OAuth callbacks, expiring tokens and leaked keys. Each guide quotes the error you see, explains the setting or code behind it, and shows how to check the fix.
- Supabase “JWT expired” – why the token went stale and how to keep it freshWhy Supabase API calls fail with 'JWT expired' (401), where stale access tokens come from in browser, server and mobile code, and how supabase-js refreshes.
- Supabase service_role or secret key exposed in frontend code – detect, rotate, fixHow to find a Supabase service_role or sb_secret_ key in your frontend bundle, why it bypasses every RLS policy, and how to rotate it and move code server-side.
- Supabase “Database error deleting user” – the foreign key on auth.usersFix 'Database error deleting user' and 'violates foreign key constraint on table profiles' (23503) when deleting a Supabase auth user: ON DELETE rules.
- Supabase “Email link is invalid or has expired” and confirmation links that open localhostWhy Supabase confirmation and magic links fail with otp_expired or redirect to localhost: Site URL, redirect allow list, link scanners and PKCE. Exact fixes.
- redirect_uri_mismatch with Supabase Google or GitHub login – which URL goes whereFix 'Error 400: redirect_uri_mismatch' (Google) and 'The redirect_uri MUST match the registered callback URL' (GitHub) with Supabase Auth social login.
- Supabase “Database error saving new user” – find the failing trigger and fix itWhy Supabase sign-up fails with 'Database error saving new user' (500): a broken handle_new_user trigger, search_path or a constraint. Find it and fix it.
- A .env file or API key in Git history – rotate first, then rewrite historyYou pushed a .env file or API key to GitHub. Rotate the secrets first, then remove them from Git history with git-filter-repo, and block the next leak.