Session.ts overview

Sessions over BetterAuth: the request lookup the SvelteKit handle and SessionResolution take, and the core’s SessionService over BetterAuth’s internal adapter.

Since v0.1.0


Exports Grouped by Category


constructors

credentialConfig

The credential naming of BetterAuth’s session cookie, for SessionResolution.detectCredential and the SvelteKit handle’s cookies option. The name is read from the instance (better-auth.session_token, or __Secure-… when the cookie is secure, under advanced.cookiePrefix), never hard-coded, with hostPrefix: false since BetterAuth sets none.

Only the session cookie is detected: BetterAuth’s cache cookie is …session_data, which the core’s ${name}_data cannot name, and it is never sent without the session cookie, so the cookieless skip stays correct.

Signature

declare const credentialConfig: (context: BetterAuthContext) => Auth.SessionResolution.CredentialConfig

Source

Since v0.1.0

layers

sessionServiceLayer

The core’s SessionService over BetterAuth’s internal adapter, for code that holds a raw token or a user id rather than a request. Sessions are named by BetterAuth’s stored session.id; the raw token is what validateSession and invalidateSession take.

  • createSession fails with AuthError: BetterAuth’s routes issue sessions and their signed cookie.
  • No effect-auth hook runs (BetterAuth’s databaseHooks still do).
  • setSessionAttributes writes only columns BetterAuth declares (activeOrganizationId, activeTeamId, additionalFields); any other key fails with AuthError.

Signature

declare const sessionServiceLayer: Layer.Layer<Auth.SessionService.SessionService, never, BetterAuthInstance>

Source

Since v0.1.0

models

SessionLookup (interface)

A lookup’s answer: the session, if any, and BetterAuth’s Set-Cookie lines (a slid session expiry, a refreshed or cleared cache cookie) for the response. Structurally the SvelteKit handle’s SessionLookup.

Signature

export interface SessionLookup {
  readonly session: Option.Option<Auth.Types.SessionWithUser>
  readonly setCookie: ReadonlyArray<string>
}

Source

Since v0.1.0

services

BetterAuthSessions (class)

The session a request carries, through BetterAuth’s own getSession.

Signature

declare class BetterAuthSessions

Source

Since v0.1.0


This site uses Just the Docs, a documentation theme for Jekyll.