@drupal-js-sdk/auth
Overview
Helpers for Drupal core session endpoints: session token, login, logout, password reset and registration. It relies on the configured HTTP client/session in your Drupal
instance.
Usage
JavaScript
import { Drupal } from "@drupal-js-sdk/core";
import { DrupalAuth } from "@drupal-js-sdk/auth";
const drupal = new Drupal({ baseURL: "https://example.com" });
const auth = new DrupalAuth(drupal);
await auth.getSessionToken();
const isLoggedIn = await auth.loginStatus();
if (!isLoggedIn) {
await auth.login("username", "password");
}
Public API
class DrupalAuth
Constructor
Example
getSessionToken
login
loginStatus
logout
passwordResetByUserName
passwordResetByMail
register
Notes
- Uses HTTP client and session from the provided
Drupal
instance. - Errors are
DrupalError
withgetErrorCode()
.