Next.js
Server sessions for the Next.js App Router.
import { … } from "@monarcode/session-kit/next";Guide: Next.js.
Functions
nextJar
The CookieJar for cookies() from next/headers, to pass to serverAuth from @monarcode/session-kit/server.
nextSession
Gives a Next.js app its session (NextSession), over nextJar and proxyJar. Make it once, beside serverAuth, in a module only server code imports.
proxyJar
The CookieJar for a request in Next's Proxy (proxy.ts). It reads request's cookies and sets new ones on response. Use it with serverAuth.refreshIfDue, so the pages that render the request see a fresh token through nextJar.
sessionRoute
Makes the Route Handlers for your session route, which answers createMirrorAuth's endpoint: the browser client reads the session, signs out and gets the access token through it. Pass cookies from next/headers (NextSessionRouteOptions).
Types
NextCookies
A request's cookie store, as cookies() from next/headers resolves it. nextJar reads and writes it, and Next's own store fits.
NextJarOptions
Options for nextJar.
Prop
Type
NextSession
The session in a Next.js app, made by nextSession: reads and guards for Server Components, the request's session for Server Functions and Route Handlers, and the refresh for Proxy.
NextSessionOptions
Options for nextSession. Pass Next's own cookies and redirect, as this entry point doesn't import next.
Prop
Type
NextSessionRoute
The Route Handlers sessionRoute makes, for GET and POST.
NextSessionRouteOptions
Options for sessionRoute. Pass Next's own cookies, as this entry point doesn't import next.
Prop
Type
ProxyRequest
The request proxyJar reads cookies from. A NextRequest fits.
ProxyResponse
The response proxyJar sets cookies on. A NextResponse fits.