Skip to main content
Utilities for managing cookies and JWT tokens in logto-authkit applications. General-purpose cookie management functions.

cookieUtils.setCookie

Set a cookie with the given name, value, and options.
string
required
The cookie name
string
required
The cookie value
CookieOptions
Cookie configuration options

CookieOptions

Date | number
Expiration date (Date object) or number of days until expiration
number
Maximum age in seconds
string
Cookie domain
string
default:"/"
Cookie path
boolean
default:"window.location.protocol === 'https:'"
Whether cookie requires HTTPS
'strict' | 'lax' | 'none'
default:"lax"
SameSite cookie attribute
boolean
Whether cookie is HTTP-only (not accessible via JavaScript)
Example:

cookieUtils.getCookie

Get a cookie value by name.
string
required
The cookie name to retrieve
Returns: string | null - The cookie value, or null if not found Example:

cookieUtils.removeCookie

Remove a cookie by name.
string
required
The cookie name to remove
RemoveCookieOptions
Cookie removal options (domain and path must match the original cookie)

RemoveCookieOptions

string
Cookie domain (must match original)
string
default:"/"
Cookie path (must match original)
Example:

JWT Token Utilities

Specialized utilities for managing JWT authentication tokens.

jwtCookieUtils.saveToken

Save a JWT token to a secure cookie.
string
required
The JWT token to save
Cookie details:
  • Name: logto_authtoken
  • Expires: 7 days
  • Secure: true (HTTPS only)
  • SameSite: strict
  • Path: /
Example:

jwtCookieUtils.getToken

Retrieve the JWT token from the cookie.
Returns: string | null - The JWT token, or null if not found Example:

jwtCookieUtils.removeToken

Remove the JWT token cookie.
Example:

Configuration Validation

validateLogtoConfig

Validate Logto configuration for required fields.
LogtoConfig
required
The Logto configuration object to validate
Throws: Error if configuration is invalid or missing required fields Example:
The library uses internal utilities for transforming user data and generating guest IDs. These utilities are used automatically by the AuthProvider and do not need to be called directly.