MIT · TypeScript · version 0.1.1
direct-auth
Sign-in on your own server, with your users in your own database. Migrate from Supabase, Firebase or Auth0 without your users losing a thing.
$ npm i direct-auth- 0
- dependencies
- 7
- ways in: Apple, Google, GitHub, email, SMS, passkeys, passwords
- 4
- runtimes: Deno, Node, Bun, Workers
- 6
- to migrate from: Supabase, Firebase, Auth0, Clerk, Auth.js, Better Auth
Quick start
- 01
npx direct-auth initWhere the server runs. It asks which ways in, checks Apple’s .p8 with Apple, sends you a test code, makes the signing key and writes the .env. On Supabase or Cloudflare it shows the secrets command and runs it if you say so.
- 02
createAuthServer({ sql, ...authFromEnv(env) })The routes your apps call: the sign-ins, the refresh, the account and its deletion, and the issuer’s keys. Its tables are made on the first start.
- 03
npx direct-auth migrateIf your users are somewhere else. It asks where from (Supabase, Firebase, Auth0, Clerk, Auth.js or Better Auth), shows what migrates before anything changes and migrates everyone in one transaction, with the way back written first. Same users, same data; they sign in again once.
- 04
npx direct-auth appIn each app’s folder. It finds the iOS, Android and web projects and adds the client.
$
With your agent
The package ships a skill for your agent: where the server runs, the wizards, how to bring your users from another service, and the rules that keep keys out of the code.
Put it in your project:
$ npx direct-auth skillClaude Code reads it when the task calls for it.
- In Claude Code, as a plugin
- /plugin marketplace add guillecura/skills /plugin install direct-auth@whitebear
- For another agent
- npx direct-auth skill --dir .agents/skills
- Without installing the package
- npx skills add guillecura/direct-auth
Add Sign in with Apple and passkeys to the iOS app.
Hands you
npx direct-auth initfor the .p8 andappfor the Swift package; you run the ones that ask for files.Migrate our users from Supabase Auth.
Goes in order: you turn sign-ins and sign-ups off in Supabase, then the dry run of
migrate, and you type themoveyourself.Let people delete their account from the app.
Uses the deletion route, which revokes Apple’s token as the App Store asks.
The server
A Supabase Edge Function, a Node process or a Worker, with its tables on the database you already have.
supabase/functions/auth/index.ts
import postgres from "npm:postgres@3";
import { authFromEnv, createAuthServer } from "npm:direct-auth@0";
import { postgresJsSql } from "npm:direct-auth@0/postgres";
const sql = postgres(Deno.env.get("SUPABASE_DB_URL")!, { prepare: false });
const server = await createAuthServer({ sql: postgresJsSql(sql), ...authFromEnv(Deno.env.toObject()) });
Deno.serve((req) => server.fetch(req));
// Authentication › Third-Party Auth: add the issuer, and auth.uid() is the user's id.The apps
One client per platform: it signs in, keeps the session on the device, refreshes the token a minute before it ends and hands it to the Supabase client.
Auth.swift
import DirectAuth
let auth = DirectAuth(url: URL(string: "https://api.example.com/auth")!)
let signIn = try await auth.signInWithApple(presentationAnchor: window)
try await auth.startEmail("[email protected]")
let byCode = try await auth.verifyEmail("[email protected]", code: code)
let passkey = try await auth.registerPasskey(anchor: window)
// supabase-swift, with direct-auth as the project's Third-Party Auth issuer
let supabase = SupabaseClient(supabaseURL: url, supabaseKey: anonKey,
options: .init(auth: .init(accessToken: { try await auth.accessToken() })))
try await auth.deleteAccount(anchor: window) // runs Sign in with Apple again when the server asks for a codeWhere it runs
Deno · Supabase
- Server
- Deno.serve(server.fetch)
- Import
- npm:direct-auth
Node 22.18+ · Bun
- Server
- serve(server), Bun.serve
- Import
- direct-auth/node
Cloudflare Workers
- Server
- server.fetch, mail over HTTP
- Import
- direct-auth
Browsers
- Server
- the client
- Import
- direct-auth/client
| Runtime | Server | Import |
|---|---|---|
| Deno · Supabase | Deno.serve(server.fetch) | npm:direct-auth |
| Node 22.18+ · Bun | serve(server), Bun.serve | direct-auth/node |
| Cloudflare Workers | server.fetch, mail over HTTP | direct-auth |
| Browsers | the client | direct-auth/client |
Accounts and sessions are kept in SQLite, Postgres (Supabase, Neon, Vercel Postgres, RDS) or Cloudflare D1: the database you already have.
What it takes care of
Apple’s revocation, done
The app’s code is kept as Apple’s refresh token, encrypted, so deleting the account revokes it, as App Store guideline 5.1.1(v) asks. Apple’s notices sign out users who leave.
Against SMS pumping
SMS goes only to the calling codes you list, and there is no default. Then limits per number, per IP, 50 an hour per country and 500 a day, kept in the database so they hold across instances.
A copied refresh token ends the session
The refresh token changes at every use and is stored as a hash. One used twice, a copy taken off a device, ends the whole session.
Passkeys with WebCrypto
WebAuthn registration and sign-in on the web, iOS and Android, checked with WebCrypto. A passkey is trusted as the key the user’s device made: no attestation asked.
Supabase keeps its data
The server publishes its OpenID discovery and its keys. Add it under Third-Party Auth, and auth.uid() in your policies is the user’s id, for the Data API, Storage and Realtime.
Leaving Supabase Auth, same ids
A SQL script you read and run copies the users and their Apple, Google, email and phone identities with the ids they had, and points your foreign keys at the new table.
Why
Apple and Google sign the tokens they give your app, and their keys are public: checking one is WebCrypto and a fetch. A code by email or SMS is six digits kept as an HMAC, and some limits. None of it needs a hosted auth service, and on your own server the users are yours, in the database the rest of your data is in.
What it gives out is a standard token: an ES256 JWT that anything trusting the server’s published keys can check. A Supabase project keeps its data and its row level security while direct-auth signs people in, since auth.uid() reads the token’s sub. And the same server runs without Supabase.
Leaving a provider shouldn’t cost you your users. The migration keeps each person as the same user (an id that isn’t a UUID gets a new one, with the old one beside it), their checked addresses and numbers, their Apple, Google and GitHub accounts and, where the provider hands them over, their passwords, checked as they were and upgraded at the next sign-in. Supabase’s anonymous users keep their account too. Each source has its own step-by-step guide.
Without
- A hosted auth service: no Auth0, no Firebase Auth
- Dependencies
- SMS to countries where you have no users
- Codes stored as they are: only an HMAC is kept
Whitebear’s own apps are moving their sign-in to it.