Returns the internal EnvConfig instance for advanced inspection.
Creates a new AuthClient instance.
Optional overrides for environment‑based configuration.
Performs the complete login flow and returns the session data.
The persisted session data (cookies, CSRF token, login flag, timestamp).
Steps:
INVALID_CREDENTIALS if missing)._token, email, and password.AuthError on failure).The method uses retries with exponential backoff for transient failures.
const session = await auth.login();
console.log(`Logged in at ${new Date(session.timestamp)}`);
console.log(`CSRF token: ${session.csrfToken}`);
Retrieves the cached session from disk without checking freshness.
The stored session, or null if no session exists or the file is corrupted.
This method does not validate the age of the session or the loggedIn flag.
Use hasValidSession for freshness and validity checks.
Checks whether a valid (fresh and logged‑in) session exists in the cache.
Maximum allowed age in milliseconds.
true if a cached session exists, is fresh, and loggedIn is true.
A session is considered valid if:
loggedIn property is true.Date.now() - session.timestamp) is less than maxAgeMs.This method does not contact the server to verify the session.
Clears both the in‑memory cookie jar and the persistent session cache.
Use this method to completely remove any stored authentication state.
After clearing, the next call to login will start a fresh login flow.
ReadonlyconfigValidated configuration object (base URL, paths, credentials).
ReadonlycacheDisk cache manager for persisting session data.
Handles saving, loading, and clearing session data from the file system.
The cache file path can be obtained via cacheFilePath.
Client for automating login against CSRF‑protected web applications.
Remarks
The client performs a two‑step login process:
After successful login, the session (cookies, CSRF token, timestamp) is saved
to disk. Subsequent calls can reuse the cached session without re‑authenticating.
The client is configurable via environment variables (
.envfile) or constructoroptions. It supports retries with exponential backoff, timeouts, and optional
Referer/Originheaders for servers that require them.Session caching:
~/.cache/libts-csrfx-auth/session.json(configurable)Example
Example
Example
Since
0.1.1
See