@propelauth/javascript
Version:
A library for managing authentication in the browser, backed by PropelAuth
61 lines (60 loc) • 2.57 kB
TypeScript
import { AuthenticationInfo } from "./api";
export interface RedirectToSignupOptions {
postSignupRedirectUrl?: string;
userSignupQueryParameters?: Record<string, string>;
}
export interface RedirectToLoginOptions {
postLoginRedirectUrl?: string;
userSignupQueryParameters?: Record<string, string>;
}
export interface RedirectToAccountOptions {
redirectBackToUrl?: string;
}
export interface RedirectToCreateOrgOptions {
redirectBackToUrl?: string;
}
export interface RedirectToOrgPageOptions {
redirectBackToUrl?: string;
}
export interface RedirectToSetupSAMLPageOptions {
redirectBackToUrl?: string;
}
export type AccessTokenForActiveOrg = {
error: undefined;
accessToken: string;
} | {
error: "user_not_in_org";
accessToken: never;
} | {
error: "unexpected_error";
accessToken: never;
};
export interface IAuthClient {
getAuthenticationInfoOrNull(forceRefresh?: boolean): Promise<AuthenticationInfo | null>;
logout(redirectAfterLogout: boolean): Promise<void>;
getSignupPageUrl(options?: RedirectToSignupOptions): string;
getLoginPageUrl(options?: RedirectToLoginOptions): string;
getAccountPageUrl(options?: RedirectToAccountOptions): string;
getOrgPageUrl(orgId?: string, options?: RedirectToOrgPageOptions): string;
getCreateOrgPageUrl(options?: RedirectToCreateOrgOptions): string;
getSetupSAMLPageUrl(orgId: string): string;
getAccessTokenForOrg(orgId: string): Promise<AccessTokenForActiveOrg>;
redirectToSignupPage(options?: RedirectToSignupOptions): void;
redirectToLoginPage(options?: RedirectToLoginOptions): void;
redirectToAccountPage(options?: RedirectToAccountOptions): void;
redirectToOrgPage(orgId?: string, options?: RedirectToOrgPageOptions): void;
redirectToCreateOrgPage(options?: RedirectToCreateOrgOptions): void;
redirectToSetupSAMLPage(orgId: string, options?: RedirectToSetupSAMLPageOptions): void;
addLoggedInChangeObserver(observer: (isLoggedIn: boolean) => void): void;
removeLoggedInChangeObserver(observer: (isLoggedIn: boolean) => void): void;
addAccessTokenChangeObserver(observer: (accessToken: string | undefined) => void): void;
removeAccessTokenChangeObserver(observer: (accessToken: string | undefined) => void): void;
destroy(): void;
}
export interface IAuthOptions {
authUrl: string;
enableBackgroundTokenRefresh?: boolean;
minSecondsBeforeRefresh?: number;
disableRefreshOnFocus?: boolean;
}
export declare function createClient(authOptions: IAuthOptions): IAuthClient;