@slashid/react
Version:
React SDK for the /id platform
94 lines • 3.73 kB
TypeScript
import { ReactNode } from "react";
import { AnonymousUser, SlashID, SlashIDEnvironment, SlashIDOptions, User } from "@slashid/slashid";
import { ThemeProps } from "@slashid/react-primitives";
import { LogIn, MFA, Recover } from "../domain/types";
import { SDKState } from "../domain/sdk-state";
export type StorageOption = "memory" | "localStorage" | "cookie";
export interface SlashIDProviderProps {
oid: string;
initialToken?: string;
tokenStorage?: StorageOption;
/**
* The environment to connect to - either "production" or "sandbox".
* @default "production"
*
* To use a custom environment, pass an object with the following shape:
* @example
* environment: {
* baseURL: "https://{YOUR_CUSTOM_API_DOMAIN}}",
* sdkURL: "https://{YOUR_CUSTOM_SDK_DOMAIN}}/sdk.html"
* }
*
*/
environment?: SlashIDEnvironment;
/**
* @deprecated Use the `environment` prop instead.
*/
baseApiUrl?: string;
/**
* @deprecated Use the `environment` prop instead.
*/
sdkUrl?: string;
analyticsEnabled?: boolean;
/**
* Anonymous users allow you to perform operations
* on users who have not signed-up or logged-in,
* using the same API as regular users.
*
* Use anonymous users to read & set user attributes, store
* GDPR consent, track sign-up conversions, and build a
* fingerprint of users who simply never sign-up.
*
* When the anonymous users signs up, or signs in, their
* anonymous user is upgraded to a full user, and their
* pre-login data is transferred.
*/
anonymousUsersEnabled?: boolean;
/**
* On init SlashID SDK will attempt to resolve supported query params to a user token.
* If this fails, the SDK will ignore the error and resume work without the initial user token.
* You can optionally register a callback to be able to react to this error.
*/
onInitError?: (e: Error) => void;
themeProps?: ThemeProps;
children: ReactNode;
}
/**
* Used to sync the React SDK internal state to external orgID/token.
*/
type ExternalStateParams = Pick<SlashIDProviderProps, "oid" | "initialToken">;
export type Subscribe = SlashID["subscribe"];
export type Unsubscribe = SlashID["unsubscribe"];
type OrgSwitchingState = {
state: "idle";
} | {
state: "switching";
oid: string;
};
export interface ISlashIDContext {
sid: SlashID | undefined;
user: User | undefined;
anonymousUser: AnonymousUser | undefined;
sdkState: SDKState;
logOut: () => undefined;
logIn: LogIn;
subscribe: Subscribe;
unsubscribe: Unsubscribe;
mfa: MFA;
recover: Recover;
validateToken: (token: string) => Promise<boolean>;
__switchOrganizationInContext: ({ oid, }: {
oid: string;
}) => Promise<User | undefined>;
__syncExternalState: (state: ExternalStateParams) => Promise<void>;
__orgSwitchingState: OrgSwitchingState;
}
export declare const initialContextValue: ISlashIDContext;
export declare const SlashIDContext: import("react").Context<ISlashIDContext>;
export declare const SlashIDProvider: ({ children, ...props }: SlashIDProviderProps) => import("react/jsx-runtime").JSX.Element;
type SlashIDProviderImplementationProps = SlashIDProviderProps & {
createSlashID: (options: SlashIDOptions) => SlashID;
};
export declare function SlashIDProviderImplementation({ oid: initialOid, initialToken, tokenStorage, environment, baseApiUrl, sdkUrl, analyticsEnabled, anonymousUsersEnabled, onInitError, themeProps, createSlashID, children, }: SlashIDProviderImplementationProps): import("react/jsx-runtime").JSX.Element;
export {};
//# sourceMappingURL=slash-id-context.d.ts.map