Skip to content

The Next.js package

For: a developer of a Next.js app on the App Router.

What it does: this page lists the exports of the package. The export check holds this page to packages/next/src/index.ts.

Export What it does
authRouteHandlers Answers { GET, POST, OPTIONS } for app/auth/[...path]/route.ts.
authSession Answers the session of a server component from its headers, or null. It renews no cookie.
authProxy Answers the proxy of proxy.ts. A request on a protected path with no session goes to the sign-in page with next.
RouteHandlerOptions The options of authRouteHandlers: waitUntil, the hook that keeps work alive after the answer. It has no default.
AuthProxyOptions The options of authProxy: protect, signInPath, auth, and cookieName.
AuthSource An auth instance, or a function that makes it at the first request.
  • A route handler of Next gets the Request only, so the binding reads no platform. Pass the hook of the host: authRouteHandlers(getAuth, { waitUntil: (p) => after(p) }), with after of next/server. On Workers pass waitUntil of cloudflare:workers. With no option, the work after the answer runs detached on Node. On Workers, handle waits for that work before it answers (ruling 29 of plan 12i).
  • The package imports nothing of Next at run time. It takes a web request and answers a web response.
  • Next 16 renamed middleware to proxy. The file is proxy.ts, and its export is proxy. For a file named middleware.ts, next build warns that the “middleware” file convention is deprecated.
  • Without auth, the proxy checks only that a session cookie is present, or a bearer that starts with ts_ (SESSION_TOKEN_PREFIX). It does not check that the session is live. Never trust the proxy alone.
  • With auth, the proxy asks core, with no write: one storage read per protected request.
  • The default cookieName is __Host-tempo_session. With the default, the proxy also reads the cookie name of before plan 12b, as core does.
  • authSession is a read with no write. A server component cannot set a cookie, so the read leaves the sliding refresh for the browser.
  • The browser gets the renewed cookie from its own read of GET /auth/session, such as the read of the session store of @authtempo/react. Other routes under /auth do not renew it.
  • An app with no such read calls /auth/session from the page. Otherwise the cookie ends at its first Max-Age.
  • It takes next 16.4 or a later 16 release as a peer dependency.