User Reference

Passage.js methods for managing a user from your frontend application.

The User class represents an authenticated Passage user. This class has methods that can be used to retrieve data on the current user which require authentication.

All methods are a part of the User class which should be used as follows:

import { Passage } from '@passageidentity/passage-js';

const passage = new Passage('YOUR_APP_ID');
const user = passage.getCurrentUser();
const userInfo = await user.userInfo();

.getCurrentUser()

This function prepares all necessary aspects of making authenticated for current user information and exposes methods that simplify the most common use cases.

User

Returns the User object that represents an authenticated user.

Current User Methods

.userInfo()

Returns the user information for the currently authenticated user.

Promise<PassageUserInfo | undefined>

Returns the Passage user object. If the user's token could not be validated, returns undefined.

interface PassageUserInfo {
    created_at: string;
    update_at: string;
    status: string;
    id: string;
    email: string;
    email_verified: boolean;
    phone: string;
    phone_verified: boolean;
    webauthn: boolean;
    webauthn_devices: PassageDevice[];
    last_login_at: string;
    login_count: number;
    user_metadata: Metadata | null;
    webauthn_types: WebAuthnType[];
}

.changeEmail(newEmail: string)

Initiates an email change for the currently authenticated user. An email will be sent to the provided email, which they will need to verify before the change takes effect.

newEmail: string

.changePhone(newPhone: string)

Initiates a phone number change for the currently authenticated user. A text will be sent to the provided phone number, which they will need to verify before the change takes effect.

newPhone: string - valid E164 formatted phone number.

.listDevices()

List devices for the current authenticated user. Device information includes the friendly name, ID, when the device was added, and when it was last used.

Promise<PassageDevice[]>

Returns a promise that resolves to a list of devices for the current user. A device represents a device or credential that can be used for a WebAuthn exchange.

interface PassageDevice {
    id: string;
    cred_id: string;
    friendly_name: string;
    usage_count: number;
    updated_at: string;
    created_at: string;
}

.editDevice(deviceID: string, editDeviceRequest: PassageEditDeviceRequest)

Edits the information about the device provided. Currently only the name can be edited.

deviceID - ID for the device to be edited. Can be found via userInfo or listDevices methods.

editDeviceRequest - new fields to edited. Currently, only the name can be changed.

.addDevice()

Adds the current device for the current authenticated user. If WebAuthn is supported by the current device and browser, the platform will request authorization from the authenticator (e.g. FaceID).

Promise<PassageDevice>

Returns a Promise that resolves to the new device that was just added. A device represents a device or credential that can be used for a WebAuthn exchange.

interface PassageDevice {
    id: string;
    cred_id: string;
    friendly_name: string;
    usage_count: number;
    updated_at: string;
    created_at: string;
    user_id: string;
}

.deleteDevice(deviceID: string)

Revokes a device for the current authenticated user. The device will no longer be able to log into the Passage account and will need to be re-added.

deviceID - ID for the device to be edited. Can be found via userInfo or listDevices methods.

Last updated