UNPKG

@0xsequence/connect

Version:
43 lines 1.46 kB
'use client'; import { useEffect, useState } from 'react'; import { useAccount, useConfig } from 'wagmi'; import { LocalStorageKey } from '../constants/localStorage.js'; /** * Hook to retrieve the email address associated with the currently connected wallet. * * This hook monitors the connection status and retrieves the stored email address when a wallet * is connected. It works with both WaaS (Wallet-as-a-Service) and universal wallet types. * The email is cleared when the wallet is disconnected. * * @see {@link https://docs.sequence.xyz/sdk/web/wallet-sdk/ecosystem/hooks/useSignInEmail} for more detailed documentation. * * @returns {string | null} The email address of the connected wallet user, or null if not connected * or no email is associated * * @example * ```tsx * const email = useSignInEmail() * if (email) { * console.log('Connected user email:', email) * } * ``` */ export const useSignInEmail = () => { const { storage } = useConfig(); const { isConnected } = useAccount(); const [email, setEmail] = useState(null); const storeEmail = async () => { const storedEmail = await storage?.getItem(LocalStorageKey.WaasSignInEmail); setEmail(storedEmail); }; useEffect(() => { if (isConnected) { storeEmail(); } else { setEmail(null); } }, [isConnected]); return email; }; //# sourceMappingURL=useSignInEmail.js.map