skip to content

// authentication service

Node auth template

Passkeys, OpenID Connect and revocable sessions in an authentication backend ready to fork.

An Express 5 and TypeScript authentication API on PostgreSQL and Prisma 7, with passwordless passkeys, TOTP recovery codes and a headless OpenID Connect provider. Rotating tokens, account self-service, reliable email delivery and tracing cover the work around sign-in too.

// padlock04/21
year
2025
type
authentication service
group
platforms and backends
stars
4

the problem

//01the problem

Authentication is more than issuing a token. People need passwordless sign-in, a way to recover a second factor, control over their sessions and their data, and an identity other apps can trust. The starter should handle those lifecycles together.

how it works

//02how it works

  1. 01

    Passkeys and a recoverable second factor

    WebAuthn passkeys support sign-in without typing an email or password, with user verification, single-use challenges and clone detection. Password sign-in can require a short-lived TOTP challenge, with encrypted secrets, replay protection and ten one-time recovery codes.

  2. 02

    An identity other apps can use

    A headless OpenID Connect provider supports authorization code flow with PKCE, discovery, userinfo and consent for third-party clients, plus token introspection and revocation endpoints. Access and ID tokens use rotating ES256 signing keys published through JWKS, so other services can verify them.

  3. 03

    Sessions you can actually end

    Opaque refresh tokens rotate on every use; reuse revokes the session. Every authenticated API request checks that its server-side session is active. Users can list sessions, revoke one, log out everywhere and inspect a paginated login history.

  4. 04

    The whole account lifecycle

    Email verification, password reset and confirmed email changes use single-use codes stored as HMACs, with attempt limits and resend cooldowns. Users can edit their profile, export their account data and delete their account after re-authentication.

  5. 05

    Security at each boundary

    Argon2id replaces bcrypt, upgrading existing hashes on sign-in. Breached password screening uses k-anonymity, failed sign-ins trigger account lockout, and recovery endpoints avoid revealing whether an account exists. Rate limits can share a Redis store, with Helmet, strict CORS and validated configuration around the API.

  6. 06

    Delivery and operations built in

    A PostgreSQL outbox commits email and security notices with the change that caused them, then retries delivery through workers. OpenTelemetry traces and business metrics, redacted structured logs, health checks and OpenAPI docs make the service inspectable. Integration tests use a real database; CI scans code and container images.

highlights

//03highlights

  • Passwordless WebAuthn passkeys and TOTP with one-time recovery codes
  • OpenID Connect with PKCE, consent and rotating ES256 keys
  • Refresh token reuse detection and immediate session revocation in the API
  • Confirmed email changes, account data export and self-service deletion
  • Transactional email outbox, security alerts and an account activity log
  • OpenTelemetry, OpenAPI, database integration tests and container security scans

built with

  • Node.js
  • TypeScript
  • Express
  • PostgreSQL
  • Prisma
  • Zod
  • WebAuthn
  • OpenID Connect
  • Argon2id
  • Redis
  • OpenTelemetry
  • Vitest
  • Docker

//04contact

Say hello. I read everything.

Email is the fastest way to reach me. For anything that needs a conversation, book a call.

to

name
Khaled Saeed
country
Lebanon