Supabase-backed authentication storage
Persisting Auth.js users and sessions in Supabase.
Auth.js · Const
SupabaseAdapter creates an Auth.js adapter backed by a Supabase database. Provide the database URL and access secret, then register the result in Auth.js configuration.
SupabaseAdapter receives the Supabase database URL and a secret, then returns an Auth.js Adapter that persists user and session data in Supabase. The integration uses a separate next_auth schema and is independent of Supabase Auth.
function SupabaseAdapter(options): Adapter| Name | Type | Description |
|---|---|---|
options | SupabaseAdapterOptions | Supabase URL and secret used to access the database. |
Adapter
import NextAuth from "next-auth";
import { SupabaseAdapter } from "@auth/supabase-adapter";
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [],
adapter: SupabaseAdapter({
url: process.env.SUPABASE_URL!,
secret: process.env.SUPABASE_SERVICE_ROLE_KEY!,
}),
});Creates an Auth.js configuration whose adapter stores authentication data in Supabase.
Persisting Auth.js users and sessions in Supabase.
Adding database persistence to a NextAuth.js application.
Using Auth.js with Supabase without using Supabase Auth.
SupabaseAdapter is a factory function that accepts SupabaseAdapterOptions and returns an Adapter. Its options include the database URL and a secret used to grant database access.
Follow-up: Where does it store Auth.js data? It uses the Supabase Database in a separate next_auth schema, rather than interfacing with Supabase Auth.
Install @supabase/supabase-js and @auth/supabase-adapter, then pass the Supabase URL and service-role key through SupabaseAdapter in the Auth.js configuration. The adapter is supplied through the adapter property.
Follow-up: What security concern follows from this setup? The secret grants database access, so it should be supplied through protected server-side environment variables rather than exposed to clients.
It stores user and session data in Supabase, but it is a standalone Auth server and does not interface with Supabase Auth. Supabase Auth is the alternative when its additional authentication features are required.
Follow-up: Which alternative should be considered for built-in email, phone, or MFA support? Use Supabase Auth with the Auth Helpers for Next.js.
SupabaseAdapterOptionsAdapter@auth/supabase-adapter@supabase/supabase-js