@salad-labs/loopz-typescript
Version:
The Official Loopz TypeScript SDK
93 lines • 3.64 kB
TypeScript
import { AuthConfig, AuthEvents, AuthInfo, LinkAccountInfo } from "./types/auth";
import { ApiKeyAuthorized, Maybe } from "./types/base";
import { AuthInternalEvents } from "./interfaces/auth/authinternalevents";
import { AuthLinkMethod } from "./types/auth/authlinkmethod";
import { Account } from ".";
/**
* Represents an authentication client that interacts with a backend server for user authentication.
*/
export declare class Auth implements AuthInternalEvents {
private static _config;
private static _instance;
private static _client;
private static _realtimeAuthorizationToken;
private static _authToken;
private static _apiKey;
private static _account;
private static _authInfo;
private static _storage;
private static _eventsCallbacks;
private static _isLoggingOut;
private static _isAuthenticated;
private static set authToken(value);
private static set account(value);
static get realtimeAuthorizationToken(): Maybe<string>;
static get apiKey(): string;
static get authToken(): Maybe<string>;
static get account(): Maybe<Account>;
static fetchTokenAttemptsRealtime: number;
static prevToken: Maybe<string>;
static get MAX_ATTEMPTS_REALTIME_FETCH_AUTH_TOKEN(): number;
private constructor();
/** static methods */
private static _generateKeys;
private static _getOrCreateUserKeys;
private static _storeUserOnLocalDB;
private static _callBackendAuthAfterOAuthRedirect;
private static _callBackendAuth;
private static _callBackendLinkAfterOAuthRedirect;
private static _callBackendLink;
private static _formatAuthParams;
private static _clearEventsCallbacks;
private static _handleDesktopAuthentication;
private static _handleDesktopLink;
static _emit(event: AuthEvents, params?: any): void;
static config(config: AuthConfig & ApiKeyAuthorized): void;
static getInstance(): Auth;
/** public instance methods */
/**
* Add a new event and the associated callback.
* @param event - The event to listen.
* @param callback - The callback related to this event.
* @param onlyOnce - An optional flag, it allows the adding of only one callback associated to this event.
*/
on(event: AuthEvents, callback: Function, onlyOnce?: boolean): void;
/**
* Remove an event and the associated callback or all the callbacks associated to that event.
* @param event - The event to unlisten.
* @param callback - The callback related to this event.
* @returns None
*/
off(event: AuthEvents, callback?: Function): void;
authenticate(): Promise<{
auth: AuthInfo;
account: Account;
}>;
sendEmailOTPCode(email: string): Promise<{
email: string;
}>;
sendPhoneOTPCode(phone: string): Promise<{
phone: string;
}>;
sendEmailOTPCodeAfterAuth(email: string): Promise<{
email: string;
}>;
sendPhoneOTPCodeAfterAuth(phone: string): Promise<{
phone: string;
}>;
/**
* call this if you want to auth the user automatically without the need of a button to authenticate.
*
* e.g. auth.ready().then(() => auth.authenticate())
*/
ready(): Promise<unknown>;
logout(): void;
isAuthenticated(): boolean;
getAuthInfo(): Maybe<AuthInfo>;
getCurrentAccount(): Maybe<Account>;
link(method: AuthLinkMethod): Promise<LinkAccountInfo>;
unlink(method: AuthLinkMethod): Promise<boolean>;
static recoverAccountFromLocalDB(): Promise<void>;
static fetchAuthToken(): Promise<void>;
}
//# sourceMappingURL=auth.d.ts.map