HBForge/Examples
20 · Integrations

Better Auth — or just use forge/auth

forge/auth ships Password, JWT, SessionManager, OAuth2 PKCE, TOTP, WebAuthn, RBAC, ApiKeyAuth, BackupCodes, AdaptiveMFA — 34 APIs, zero deps.

forge/serverforge/authNodeBunDenoCF Workers
Code
better-auth.js
const { WebApp }         = require(class="tk-str">'@hyperbridge/forge/server');
const { Password, JWT }  = require(class="tk-str">'@hyperbridge/forge/auth');

const app   = new WebApp();
const users = new Map();

app.post(class="tk-str">'/signup', async (c) => {
  const { email, password } = await c.req.json();
  users.set(email, { hash: await Password.hash(password) });
  return c.json({
    token: JWT.sign({ email }, process.env.JWT_SECRET),
  });
});

app.post(class="tk-str">'/login', async (c) => {
  const { email, password } = await c.req.json();
  const u = users.get(email);
  if (!u || !(await Password.verify(password, u.hash))) {
    return c.json({ error: class="tk-str">'invalid' }, 401);
  }
  return c.json({
    token: JWT.sign({ email }, process.env.JWT_SECRET),
  });
});

app.listen(3000);
How it works

Password.hash uses argon2id by default with sane work factors (memory: 64MB, time: 3 iterations).

JWT.sign and JWT.verify are built on Web Crypto, so they work identically on Node, Bun, Deno, and CF Workers — no native binary.

For sessions instead of JWTs, swap to SessionManager with a backing store (memory, Redis, file, or your own driver).

Try it
Quickstart
curl -X POST http://localhost:3000/signup -d '{"email":"a@b.c","password":"…"}'
Related modules