PT

@yohangel / auth

1.0.0 ▾
MIT
GitHub

Login seguro com Better Auth + Drizzle: e-mail/senha, GitHub/Google, 2FA, limites e CSRF

Código6 arquivosContexto~812 tokensMCP better-authanálise aprovada

A árvore exata que será injetada, após o .genpmignore. Fixada em

src/lib/auth/db.tssomente leitura · 7145b9d
// Base de datos de @yohangel/auth: cualquier Drizzle sobre Postgres (postgres-js, Neon, PGlite…). Si tu app ya
// tiene un cliente Drizzle, pásalo con `createAuth({ db })` o `setAuthDb(db)`; si no, se crea desde DATABASE_URL.
import type { PgDatabase, PgQueryResultHKT } from 'drizzle-orm/pg-core';
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';

// biome-ignore lint/suspicious/noExplicitAny: acepta el Drizzle de la app con cualquier esquema.
export type AuthDb = PgDatabase<PgQueryResultHKT, any>;

let current: AuthDb | null = null;

export function setAuthDb(db: AuthDb): void {
  current = db;
}

export function getAuthDb(): AuthDb {
  if (current) return current;
  const url = process.env.DATABASE_URL;
  if (!url) throw new Error('DATABASE_URL is not set (or pass `db` to createAuth)');
  current = drizzle(postgres(url, { max: 5, prepare: false })) as unknown as AuthDb;
  return current;
}

Denunciar @yohangel/auth

Entre com o GitHub para denunciar um pacote.