@superdb/auth-js
v0.1.0
Published
JavaScript/TypeScript client for SuperDB Auth — supabase-js compatible API
Readme
@superdb/auth-js
Cliente JavaScript/TypeScript para o SuperDB Auth. API alinhada com [email protected] por design — para reduzir fricção de migração de projetos Supabase.
Install
npm install @superdb/auth-js
# ou
bun add @superdb/auth-js
# ou
pnpm add @superdb/auth-jsQuickstart
import { createSuperDB } from '@superdb/auth-js';
const sdb = createSuperDB({
url: 'https://acme.superdb.com.br',
project: 'acme', // header X-SuperDB-Project (Sprint 2). Custom domain resolve automático.
});
// Email + senha
const { data, error } = await sdb.auth.signUp({
email: '[email protected]',
password: 'minhaSenhaForte!2026',
});
// Magic link (link clicável por email)
await sdb.auth.signInWithOtp({ email: '[email protected]' });
// OTP por email (codigo de 6 digitos)
await sdb.auth.signInWithOtp({
email: '[email protected]',
options: { channel: 'email' },
});
const verify = await sdb.auth.verifyOtp({
email: '[email protected]',
code: '123456',
});
// OAuth (Google / GitHub / Apple)
const { data: oauth } = await sdb.auth.signInWithOAuth({ provider: 'google' });
window.location.href = oauth!.url;
// MFA (TOTP)
const { data: factor } = await sdb.auth.mfa.enroll({ factorType: 'totp', label: 'iPhone' });
// usuario escaneia factor.uri (otpauth://...) com Google Authenticator / 1Password
await sdb.auth.mfa.verify({ factorType: 'totp', code: '123456' });
// Sessao
const { data: { session } } = await sdb.auth.getSession();
const { data: { user } } = await sdb.auth.getUser();
await sdb.auth.refreshSession();
await sdb.auth.signOut();Storage
Por default: localStorage no browser, MemoryStorage no Node/Bun. Customize com storage:
import { createSuperDB, type SessionStorage } from '@superdb/auth-js';
const cookieStorage: SessionStorage = {
getItem(k) { return null; /* ler de cookie httpOnly */ },
setItem(k, v) { /* cookie set */ },
removeItem(k) { /* cookie clear */ },
};
const sdb = createSuperDB({
url: 'https://acme.superdb.com.br',
project: 'acme',
storage: cookieStorage,
});SessionStorage aceita retornos sincronos OU Promise para todas as operacoes.
Migrating from @supabase/supabase-js
Use @superdb/client (drop-in replacement):
- import { createClient } from '@supabase/supabase-js';
+ import { createClient } from '@superdb/client';
const client = createClient('https://acme.superdb.com.br', 'anon-key', { project: 'acme' });
const { data } = await client.auth.signInWithPassword({ email, password });No Sprint 2 apenas
client.auth.*esta implementado.client.from,client.storage,client.rpceclient.channellancam erro com mensagem clara apontando para alternativas.
API
| Metodo | Description |
| --- | --- |
| auth.signUp(input) | Cria usuario com email+senha (ou phone+senha) |
| auth.signInWithPassword(input) | Login com email+senha |
| auth.signInWithOtp(input) | Solicita OTP/magic link por email |
| auth.verifyOtp({ email, code }) | Verifica codigo OTP |
| auth.signInWithOAuth({ provider }) | Inicia fluxo OAuth (google/github/apple) |
| auth.signOut(scope?) | Faz logout ('local' default ou 'global') |
| auth.refreshSession() | Rotaciona refresh token |
| auth.getSession() | Retorna sessao em cache (sem chamar API) |
| auth.getUser() | Busca usuario atual via API |
| auth.mfa.enroll({ factorType }) | Inscreve TOTP/backup factor |
| auth.mfa.verify({ factorType, code }) | Verifica codigo de factor |
| auth.mfa.factors() | Lista factors do usuario |
Todas retornam { data, error } ou { data: null, error: AuthError }.
License
MIT — (c) 2026 SuperDB
