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.
Before you start
Section titled “Before you start”- Read Mount authtempo in Next.js for the steps.
Exports
Section titled “Exports”| 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. |
How it behaves
Section titled “How it behaves”- 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) }), withafterofnext/server. On Workers passwaitUntilofcloudflare:workers. With no option, the work after the answer runs detached on Node. On Workers,handlewaits 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 isproxy. For a file namedmiddleware.ts,next buildwarns that the “middleware” file convention is deprecated. - Without
auth, the proxy checks only that a session cookie is present, or a bearer that starts withts_(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
cookieNameis__Host-tempo_session. With the default, the proxy also reads the cookie name of before plan 12b, as core does. authSessionis 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/authdo not renew it. - An app with no such read calls
/auth/sessionfrom the page. Otherwise the cookie ends at its firstMax-Age. - It takes
next16.4 or a later 16 release as a peer dependency.