Skip to main content

Utils

@loginid/websdk3Docs


@loginid/websdk3 / Internal Modules / Utils

Class: Utils

Provides a base class for integrating with the LoginID API services. This class initializes the common configuration and service needed for derived classes to interact with LoginID services.

Extends

Extended by

Constructors

new Utils()

new Utils(config): Utils

Initializes a new Utils instance with the provided configuration.

Parameters

config: LoginIDConfig

Configuration object for LoginID.

Returns

Utils

Overrides

LoginIDBase.constructor

Properties

session

readonly session: SessionManager

Instance of SessionManager, providing access to the session management methods.

Inherited from

LoginIDBase.session

Methods

getSessionInfo()

getSessionInfo(): null | SessionInfo

Check whether the user of the current browser session is authenticated and returns user info. This info is retrieved locally and no requests to backend are made.

Returns

null | SessionInfo

The currently authenticated user's information, including username and id.

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);
const username = "billy@loginid.io";

try {
// Retrieve session information
await lid.authenticateWithPasskey(username);
const sessionInfo = lid.getSessionInfo();
console.log("Session Information:", sessionInfo);
} catch (error) {
console.error("Error retrieving session information:", error);
}

logout()

logout(): void

Clears current user session. This method is executed locally and it just deletes authorization token from local Cookies.

Returns

void

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

// Use the SDK components for signup and signin
const lid = new LoginIDWebSDK(config);

try {
// Retrieve user information
await lid.authenticateWithPasskey(username);
lid.logout();
const info = lid.getSessionInfo();
// false
console.log("Is user signed in?", info !== null);
} catch (error) {
console.error("Error:", error);
}

verifyConfigSettings()

verifyConfigSettings(): Promise<VerifyConfigResult>

Validates the application's configuration settings and provides a suggested correction if any issues are detected.

Returns

Promise<VerifyConfigResult>

The result of the verification process.

Example

import { LoginIDWebSDK } from "@loginid/websdk3";

// Obtain credentials from LoginID
const BASE_URL = process.env.BASE_URL;

// Initialize the SDK with your configuration
const config = {
baseUrl: BASE_URL,
};

const lid = new LoginIDWebSDK(config);

async function checkConfig() {
const result = await lid.verifyConfigSettings();

if (result.isValid) {
console.log('Configuration is valid');
} else {
console.error(`Error: ${result.message} (Code: ${result.code})`);
console.info(`Solution: ${result.solution}`);
}
}

checkConfig();

// Attach the click handler to a button
const checkConfigButton = document.getElementById("button");
checkConfigButton.addEventListener("click", checkConfig);