@propelauth/react
Version:
A React library for managing authentication, backed by PropelAuth
65 lines (64 loc) • 3.19 kB
TypeScript
import { AccessTokenForActiveOrg, AuthenticationInfo, IAuthClient, RedirectToAccountOptions, RedirectToCreateOrgOptions, RedirectToLoginOptions, RedirectToOrgPageOptions, RedirectToSetupSAMLPageOptions, RedirectToSignupOptions } from "@propelauth/javascript";
import React from "react";
export interface Tokens {
getAccessTokenForOrg: (orgId: string) => Promise<AccessTokenForActiveOrg>;
getAccessToken: () => Promise<string | undefined>;
}
export interface InternalAuthState {
loading: boolean;
authInfo: AuthenticationInfo | null;
logout: (redirectOnLogout: boolean) => Promise<void>;
activeOrgFn: () => string | null;
redirectToLoginPage: (options?: RedirectToLoginOptions) => void;
redirectToSignupPage: (options?: RedirectToSignupOptions) => void;
redirectToAccountPage: (options?: RedirectToAccountOptions) => void;
redirectToOrgPage: (orgId?: string, options?: RedirectToOrgPageOptions) => void;
redirectToCreateOrgPage: (options?: RedirectToCreateOrgOptions) => void;
redirectToSetupSAMLPage: (orgId: string, options?: RedirectToSetupSAMLPageOptions) => 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, options?: RedirectToSetupSAMLPageOptions): string;
authUrl: string;
tokens: Tokens;
refreshAuthInfo: () => Promise<void>;
defaultDisplayWhileLoading?: React.ReactElement;
defaultDisplayIfLoggedOut?: React.ReactElement;
}
declare type BaseAuthProviderProps = {
defaultDisplayWhileLoading?: React.ReactElement;
defaultDisplayIfLoggedOut?: React.ReactElement;
getActiveOrgFn?: () => string | null;
children?: React.ReactNode;
};
declare type AuthProviderWithAuthUrl = BaseAuthProviderProps & {
authUrl: string;
minSecondsBeforeRefresh?: number;
client?: never;
};
declare type AuthProviderWithClient = BaseAuthProviderProps & {
client: IAuthClient;
authUrl?: never;
minSecondsBeforeRefresh?: never;
};
export declare type AuthProviderProps = AuthProviderWithAuthUrl | AuthProviderWithClient;
declare type BaseRequiredAuthProviderProps = Omit<BaseAuthProviderProps, "defaultDisplayWhileLoading" | "defaultDisplayIfLoggedOut"> & {
displayWhileLoading?: React.ReactElement;
displayIfLoggedOut?: React.ReactElement;
};
declare type RequiredAuthProviderWithAuthUrl = BaseRequiredAuthProviderProps & {
authUrl: string;
minSecondsBeforeRefresh?: number;
client?: never;
};
declare type RequiredAuthProviderWithClient = BaseRequiredAuthProviderProps & {
client: IAuthClient;
authUrl?: never;
minSecondsBeforeRefresh?: never;
};
export declare type RequiredAuthProviderProps = RequiredAuthProviderWithAuthUrl | RequiredAuthProviderWithClient;
export declare const AuthContext: React.Context<InternalAuthState | undefined>;
export declare const AuthProvider: (props: AuthProviderProps) => JSX.Element;
export {};