UNPKG

@auth0/auth0-spa-js

Version:

Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE

110 lines (109 loc) 5.24 kB
import { Fetcher } from '../fetcher'; import type { ConnectRequest, ConnectResponse, CompleteRequest, CompleteResponse, ErrorResponse, Factor, AuthenticationMethod, AuthenticationMethodType, UpdateAuthenticationMethodRequest, EnrollmentChallengeOptions, EnrollmentChallengeResponse, EnrollmentVerifyOptions } from './types'; export type { ConnectRequest, ConnectResponse, CompleteRequest, CompleteResponse, ErrorResponse, Factor, AuthenticationMethod, AuthenticationMethodType, UpdateAuthenticationMethodRequest, EnrollmentChallengeOptions, EnrollmentChallengeResponse, EnrollmentVerifyOptions } from './types'; /** * Client for Auth0 MyAccount API operations. * * Provides methods for managing the current user's account: * - Connected accounts (link/unlink external identity providers) * - MFA factors * - Authentication methods (passkeys, phone, email, TOTP) - list, get, update, delete * - Authentication method enrollment (challenge and verify) */ export declare class MyAccountApiClient { private myAccountFetcher; private apiBase; constructor(myAccountFetcher: Fetcher<Response>, apiBase: string); /** * Get a ticket for the connect account flow. * * @param params - Connection parameters including connection name and redirect URI * @returns A promise that resolves to a connect response with the redirect URI and auth session */ connectAccount(params: ConnectRequest): Promise<ConnectResponse>; /** * Verify the redirect from the connect account flow and complete the connecting of the account. * * @param params - Completion parameters including auth session, connect code, and redirect URI * @returns A promise that resolves to the completed connected account details */ completeAccount(params: CompleteRequest): Promise<CompleteResponse>; /** * Get the status of all factors for the current user. * * @returns A promise that resolves to an array of factors with their enabled/disabled status */ getFactors(): Promise<Factor[]>; /** * Get a list of all authentication methods for the current user. * * @param type - Optional filter to return only methods of a specific type * @returns A promise that resolves to an array of authentication methods */ getAuthenticationMethods(type?: AuthenticationMethodType): Promise<AuthenticationMethod[]>; /** * Get an authentication method by ID. * * @param id - The ID of the authentication method to retrieve * @returns A promise that resolves to the authentication method */ getAuthenticationMethod(id: string): Promise<AuthenticationMethod>; /** * Delete an authentication method by ID. * * @param id - The ID of the authentication method to delete * @returns A promise that resolves when the authentication method has been deleted */ deleteAuthenticationMethod(id: string): Promise<void>; /** * Update details of an authentication method by ID. * * @param id - The ID of the authentication method to update * @param data - The fields to update (e.g. name, preferred_authentication_method for phone) * @returns A promise that resolves to the updated authentication method */ updateAuthenticationMethod(id: string, data: UpdateAuthenticationMethodRequest): Promise<AuthenticationMethod>; /** * Start the enrollment of an authentication method for the current user. * The response shape varies by type. * * @param options - Enrollment challenge options specifying the factor type and any type-specific fields * @returns A promise that resolves to the enrollment challenge response (shape varies by type) */ enrollmentChallenge(options: EnrollmentChallengeOptions): Promise<EnrollmentChallengeResponse>; /** * Confirm the enrollment of an authentication method to complete registration. * * @param options - Enrollment verify options including the auth session and type-specific verification data * @returns A promise that resolves to the confirmed authentication method */ enrollmentVerify(options: EnrollmentVerifyOptions): Promise<AuthenticationMethod>; private _handleResponse; } /** * Error thrown when the MyAccount API returns a non-2xx response. * * @example * ```typescript * try { * await myAccount.getAuthenticationMethods(); * } catch (err) { * if (err instanceof MyAccountApiError) { * console.error(err.status, err.title, err.detail); * } * } * ``` */ export declare class MyAccountApiError extends Error { /** RFC 7807 error type identifier */ readonly type: string; /** HTTP status code */ readonly status: number; /** Short human-readable summary of the error */ readonly title: string; /** Human-readable explanation specific to this occurrence */ readonly detail: string; /** Field-level validation errors, if present */ readonly validation_errors?: ErrorResponse['validation_errors']; constructor({ type, status, title, detail, validation_errors }: ErrorResponse); }