npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kamaalio/kamaal-auth-hono

v0.0.4

Published

Mountable Hono auth router. A thin adapter over @kamaalio/kamaal-auth-core, which holds the logic.

Downloads

476

Readme

@kamaalio/kamaal-auth-hono

A mountable Hono authentication router. It adapts @kamaalio/kamaal-auth-core to Hono and re-exports the core package, so this is the only Kamaal Auth package most Hono applications need to install.

Your application supplies the hooks that call its auth library and database. This package supplies route registration, session middleware, OpenAPI route definitions, request validation, and conversion between Hono contexts and the framework-neutral engine.

Install

npm install @kamaalio/kamaal-auth-hono hono @hono/zod-openapi zod

Node.js 24 or newer is required.

Quick start

import { OpenAPIHono } from '@hono/zod-openapi';
import { authHookSuccess, createAuthModule, defineAuthHooks } from '@kamaalio/kamaal-auth-hono';

const hooks = defineAuthHooks({
  async signUp(c, input) {
    return authHookSuccess(await appAuth.signUp(c.request, input));
  },
  async signIn(c, input) {
    return authHookSuccess(await appAuth.signIn(c.request, input));
  },
  async signOut(c) {
    return authHookSuccess({ headers: await appAuth.signOut(c.request) });
  },
  async getSession(c) {
    return authHookSuccess(await appAuth.getSession(c.request));
  },
  async issueToken(c) {
    return authHookSuccess(await appAuth.issueToken(c.request));
  },
  async jwks(c) {
    return appAuth.jwks(c.request);
  },
});

const app = new OpenAPIHono();
const auth = createAuthModule({
  hooks,
  config: {
    basePath: '/api/auth',
    trustedOrigins: ['myapp://'],
    session: { expiresInSeconds: 60 * 60 * 24 * 30, updateAgeSeconds: 60 * 60 * 24 },
    jwt: {
      issuer: 'https://api.example.com',
      audience: 'myapp',
      expiresInSeconds: 60 * 60,
      jwksUrl: new URL('https://api.example.com/api/auth/jwks'),
    },
  },
});

app.route('/api/auth', auth.router);

The hooks are intentionally application-owned: they can call any auth library, use any database, and return authHookFailure when that dependency reports an expected failure. See the core package for the full hook contract and standalone-engine use.

Routes

Mounting the router registers these relative paths:

| Method | Path | Purpose | | ------ | ---------------- | ---------------------------------------- | | POST | /sign-up/email | Create an account and return credentials | | POST | /sign-in/email | Authenticate with email and password | | POST | /sign-out | End the current session | | GET | /session | Return the authenticated session | | GET | /token | Issue or refresh a bearer JWT | | GET | /jwks | Serve the public JWKS document |

Successful sign-in, sign-up, and token responses use the shared credential headers: set-auth-token, set-auth-token-expiry, set-session-token, and set-session-update-age.

Protect application routes

Use requireSessionMiddleware before routes that require a session, then retrieve the resolved session with getSession. Session resolution is cached for the lifetime of the Hono request.

app.get('/api/me', auth.requireSessionMiddleware, c => {
  const session = auth.getSession(c);
  return c.json({ user: session.user });
});

Bearer JWTs are verified with the configured JWKS. Opaque bearer tokens and cookie sessions fall back to your getSession hook.

Integration points

Pass router when your app already has an OpenAPIHono instance and its validation hook/error envelope should also govern the auth routes. locals, logger, and requestId derive per-request values for every hook. payloadSchemas supports wider sign-in/sign-up payloads, sessionExtras extends session responses and OpenAPI schemas, and extraRoutes mounts app-owned routes with the auth schemas and session middleware available.

The optional fallback hook receives unmatched GET and POST auth paths after the built-in routes, which is useful for forwarding auth-library endpoints not represented by this router.

License

MIT