Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Supabase 5 min read Announcement mediumAdept

Multi-factor Authentication via Row Level Security Enforcement

Supabase Auth now offers TOTP-based multi-factor authentication to all users, built around separate enroll, challenge and verify endpoints. The challenge step is kept apart from verification so the flow can later support devices like Yubikeys. Issued JWTs carry an Authenticator Assurance Level claim (aal1 or aal2) and an Authenticator Method Reference claim listing the methods used, so Postgres Row Level Security policies can enforce MFA for all users or only for users with a verified factor. Those policies must be declared restrictive, because Postgres ORs permissive policies together.

Assumes: JWT basicsPostgres Row Level Security

Related posts

  • How to Set Up Row-Level Security in Postgres Using AWS Cognito

    Neon mediumAdept

    Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like `sub` into Postgres session variables. A `notes` table gets an RLS policy comparing `user_id` to `current_setting('jwt.claims.sub')`, so each user sees only their own rows. The demo app uses Express.js, HTMX and the Neon serverless driver, with step-by-step setup for Cognito, the database schema, environment variables and policy verification. Neon has since folded this functionality into the Neon Data API.

  • Supabase Auth: SSO, Mobile, and Server-side support

    Supabase mediumAdept

    Supabase Auth adds SAML 2.0 single sign-on, a PKCE authorization flow for server-side rendering and mobile apps, and native Sign in with Apple on iOS. SSO providers are managed with new `supabase sso` CLI commands, and the provider identifier in the JWT can drive Postgres Row Level Security policies for multi-tenant isolation. PKCE replaces the implicit grant flow, which exposed tokens in URL fragments that servers can't read and that malicious mobile apps could intercept. It does this with a hashed code verifier and challenge, so an intercepted authorization code is useless on its own. Enabling it means setting `flowType: 'pkce'` in supabase-js, and a Next.js callback route exchanges the code for a session.

  • Introducing Neon RLS: Simplifying Row-Level Security For Postgres

    Neon mediumAdept

    Neon RLS lets Postgres row-level security policies authenticate requests with JWTs from any auth provider that exposes a JWKS URL. The Neon Proxy verifies the token and exposes its claims through auth.user_id() and auth.session() from the open-source pg_session_jwt extension, for use in RLS policies and WHERE clauses. A Drizzle ORM integration adds pgPolicy and crudPolicy helpers so policies are declared alongside the schema. Neon recommends RLS for core authorization rules such as multi-tenant isolation, keeping intricate access logic in backend code, and says backend-less client apps are only suitable for simple projects.

  • Supabase Realtime: Broadcast and Presence Authorization

    Supabase mediumAdept

    Supabase Realtime now supports authorization for Broadcast and Presence channels using Postgres Row Level Security policies on a managed `realtime.messages` table, where SELECT policies govern receiving and INSERT policies govern sending. Clients opt in with a `private: true` channel config, and policies can reference the channel name via `realtime.topic()` and the extension column. On subscription, the server loads JWT claims into a Postgres transaction with `set_config`, runs rolled-back SELECT/INSERT probes against the table, and caches the resulting per-socket policy map in memory. This adds latency only at connect time, and policies are re-checked on reconnect or token refresh, so token expiry controls how quickly policy changes take effect.

  • Partial data dumps using Postgres Row Level Security

    Supabase mediumAdept

    Postgres Row Level Security can produce a seed.sql containing only safe, non-customer rows: create a restricted `exporter` role, attach RLS select policies that filter which rows it can see, then run `pg_dump --data-only --enable-row-security` as that role. Example policies filter by hardcoded IDs, email domain, recency (e.g. last two months of analytics events), or an `is_exportable` flag column. Alternatives include fully masked database copies (Snaplet) and copy-on-write database forking (Database Lab Engine on ZFS).

The quest for software engineering knowledge.

Look:
Layout: