UNPKG

@trimble-oss/trimble-id-react

Version:

> **Important Notice:** > > As of version 1.0.0, `PersistentOptions` have been removed. By default, the SDK now supports in-memory token storage. > > When you upgrade to version 1.x, storage options will no longer be available, resulting in a breaking

91 lines (90 loc) 4.51 kB
import { TIDAuthState } from './state'; import { AuthState, TokenResponse } from '../TIDClient'; export interface LoginWithRedirectOptions { /** * Function called when the user redirection is occurring * If you send this function you will need to handle the redirection * @param {string} url - Redirect url to TID with the necessary information to log in the user */ onRedirect?: (url: string) => void; } export interface LogoutOptions { /** * Function called when the user redirection is occurring * If you send this function you will need to handle the redirection * @param {string} url - Redirect url to TID with the necessary information to log out the user */ onRedirect?: (url: string) => void; /** * If you want to disable the auto redirect to TID after the logout is successful you can set this to true * If you set this to true you will need to handle the redirection and the provider will clear the user information from the context * * **IMPORTANT**: If you set this to true the user information will be cleared from the context and isAuthenticated will be false * if you are using the AuthenticationGuard component it will redirect the user to the login page automatically * @default false * @type {boolean} * @example * logout({disabledAutoRedirect: true}) */ disabledAutoRedirect?: boolean; } export interface TIDContextState extends TIDAuthState { /** * Authenticated the user using the url callback params, * After the login is successful will load the user in TIDProvider context * That way it can be access thought the whole react application * @param {string} url - Custom configuration for teh redirection * @return {Promise<AuthState>} Object contain the state returned from TID * @throws {CodeVerifierNotFoundException} Will throw an exception if the session doesn't contain the code verifier * @example No configuration * handleCallback() * // Will automatically take the url from the browser and try to log in the user * @example Custom url * handleCallback('https://example.com?code=code....') * // Will try to log in the user with the url assign by the developer */ handleCallback: (url?: string) => Promise<AuthState>; /** * Gets the access token from cache if the token already expired, * will try to refresh it using the refresh token. * In case that the user change it store the new user information in context * @return {Promise<string>} Access token * @throws {TokenNotFoundException} Will throw an exception there are not access token in cache * @throws {TokenExpiredException} Will throw an if the user token expired */ getAccessTokenSilently: () => Promise<string>; /** * Gets the token details from cache. * @return {Promise<TokenResponse>} token response * @throws {TokenNotFoundException} Will throw an exception there are no tokens in cache * @throws {TokenExpiredException} Will throw an if the user token expired */ getTokens: () => Promise<TokenResponse>; /** * Redirect the user to TID using the browser * @param {LoginWithRedirectOptions} options - Custom configuration for teh redirection * @return {Promise<void>} Empty promise * @example No configuration * loginWithRedirect() * // Automatically redirects the user to TID with all necessary parameters * @example Custom redirect * loginWithRedirect({onRedirect: (url) => router.navigate(url)}) * // Redirect calls the onRedirect and pass through the url for TID redirection to the function * // So it can be handled by the developer */ loginWithRedirect: (options?: LoginWithRedirectOptions) => Promise<void>; /** * Redirect the user to TID using the browser * @param {LogoutOptions} options - Custom configuration for teh redirection * @return {Promise<void>} Empty promise * @example No configuration * logout() * // Automatically redirects the user to TID to log out * @example Custom redirect * logout({onRedirect: (url) => router.navigate(url)}) * // Redirect calls the onRedirect and pass through the log-out url for TID to the function * // So it can be handled by the developer */ logout: (options?: LogoutOptions) => Promise<void>; } export declare const TIDContext: import("react").Context<TIDContextState | null>;