Skip to Content
Reference

Server

Sessions kept on the server, in an encrypted cookie.

import { … } from "@monarcode/session-kit/server";

Guide: Server sessions.

Functions

createServerAuth

Creates the server side of Session kit (ServerAuth). It keeps both tokens and the user in an encrypted, httpOnly cookie, so page scripts never see the refresh token.

sessionHandler

Makes the handler for your session route (SessionHandler), which answers createMirrorAuth's endpoint. A GET reads the session. A POST signs out, or gets or renews the access token for page scripts.

Types

ClientCredentials

The access token as your server gives it to the browser, from serverAuth.clientCredentials in @monarcode/session-kit/server. expiresIn counts from when the server answered, so the browser's clock doesn't matter.

CookieJar

Reads and writes one request's cookies, for createServerAuth's methods. The framework adapters, such as nextJar and startJar, build one. Elsewhere, wrap the request's cookies and the response's Set-Cookie.

Prop

Type

CookieOptions

The session cookie's attributes, as CookieJar's set and delete receive them. Every framework's cookie API takes this shape, or maps from it in a line.

Prop

Type

RefreshIfDueOptions

Options for ServerAuth's refreshIfDue.

Prop

Type

RequestAuth

One request's session: what ServerAuth does for a request, without its CookieJar. startAuth from @monarcode/session-kit/tanstack-start/server and routerAuth from @monarcode/session-kit/react-router/server give you one, and so do readOnly() and writable() from nextSession in @monarcode/session-kit/next. Elsewhere, serverAuth.forRequest(jar) does.

ServerAuth

The server side of Session kit, from createServerAuth. It keeps the session in an encrypted cookie.

ServerAuthOptions

Options for createServerAuth. user, refresh, revoke, maxAge and debug work as they do for createAuth.

Prop

Type

SessionCookieOptions

The session cookie's attributes: the cookie option of ServerAuthOptions. The cookie is always httpOnly.

Prop

Type

SessionHandler

Answers the browser client's requests to your session route, for one request and its cookie jar. sessionHandler makes one.

SessionMiddlewareOptions

Options for the middleware that refreshes before each request: refreshSession from @monarcode/session-kit/tanstack-start/server and sessionMiddleware from @monarcode/session-kit/react-router/server.

Prop

Type

On this page