@0xsequence/connect
Version:
Connect package for Sequence Web SDK
78 lines • 2.73 kB
TypeScript
import { type SignInResponse } from '@0xsequence/waas';
import type { ExtendedConnector } from '../types.js';
interface SuccessResultV1 {
version: 1;
idToken: string;
}
interface SuccessResultV2 {
version: 2;
signInResponse: SignInResponse;
}
/**
* Hook to handle email-based authentication flow for WaaS (Wallet-as-a-Service).
*
* This hook manages the complete email authentication process, including:
* - Initiating email authentication
* - Handling verification code submission
* - Managing loading and error states
* - Supporting both v1 (idToken) and v2 (SignInResponse) authentication formats
*
* @param {ExtendedConnector} [params.connector] - The WaaS connector to use for authentication.
* Optional because the user might not have selected a connector yet.
* @param {Function} params.onSuccess - Callback function called when authentication succeeds.
* Receives either a v1 result (with idToken) or v2 result (with SignInResponse).
*
* @returns {Object} An object containing:
* - `inProgress` - Whether authentication is currently in progress
* - `loading` - Whether a specific authentication operation is loading
* - `error` - Any error that occurred during authentication
* - `initiateAuth` - Function to start the email authentication process
* - `sendChallengeAnswer` - Function to submit the verification code
* - `cancel` - Function to cancel the authentication process
* - `resetError` - Function to clear any error state
*
* @example
* ```tsx
* const {
* inProgress,
* loading,
* error,
* initiateAuth,
* sendChallengeAnswer,
* resetError
* } = useEmailAuth({
* connector: emailConnector,
* onSuccess: async (result) => {
* if ('signInResponse' in result) {
* // Handle v2 authentication
* await storage.setItem('email', result.signInResponse.email)
* } else {
* // Handle v1 authentication
* await storage.setItem('idToken', result.idToken)
* }
* }
* })
* ```
*/
export declare function useEmailAuth({ connector, onSuccess }: {
connector?: ExtendedConnector;
onSuccess: (result: SuccessResultV1 | SuccessResultV2) => void;
}): {
inProgress: boolean;
loading: boolean;
error: undefined;
initiateAuth: (_email: string) => Promise<void>;
sendChallengeAnswer: (_answer: string) => Promise<void>;
resetError: () => void;
cancel?: undefined;
} | {
inProgress: boolean;
loading: boolean;
error: Error | undefined;
initiateAuth: (email: string) => Promise<void>;
sendChallengeAnswer: (answer: string) => Promise<void>;
cancel: () => void;
resetError: () => void;
};
export {};
//# sourceMappingURL=useWaasEmailAuth.d.ts.map