HBForge/Examples
24 · Integrations

Auth.js (NextAuth) under WebApp

Mount Auth.js's universal handler under a wildcard. c.req.raw is the underlying Request; Auth.js handles cookies, sessions, OAuth callbacks.

forge/serverNodeBunDenoCF Workers
Code
hono-authjs.js
const { WebApp } = require(class="tk-str">'@hyperbridge/forge/server');
const { Auth }   = require(class="tk-str">'@auth/core');
const GitHub    = require(class="tk-str">'@auth/core/providers/github').default;

const app = new WebApp();

app.all(class="tk-str">'/auth/*', (c) => Auth(c.req.raw, {
  secret: process.env.AUTH_SECRET,
  providers: [GitHub({
    clientId:     process.env.GITHUB_ID,
    clientSecret: process.env.GITHUB_SECRET,
  })],
}));

app.listen(3000);
How it works

Auth.js's Auth() function takes a standard Fetch Request and returns a Response — perfect match for c.req.raw.

All Auth.js providers (50+) work unchanged: GitHub, Google, Apple, Discord, Auth0, Okta, custom OAuth2/OIDC, magic links, credentials.

Add middleware before the catch-all for rate limiting, IP allow-listing, or per-route session checks.

Try it
Quickstart
open http://localhost:3000/auth/signin/github
Related modules