import { useNostr } from '@nostrify/react'; import { NLogin, useNostrLogin } from '@nostrify/react/login'; import type { NostrConnectParams } from '@nostrify/react/login'; // NOTE: This file should not be edited except for adding new login methods. export function useLoginActions() { const { nostr } = useNostr(); const { logins, addLogin, removeLogin } = useNostrLogin(); return { // Login with a Nostr secret key nsec(nsec: string): void { const login = NLogin.fromNsec(nsec); addLogin(login); }, // Login with a NIP-46 "bunker://" URI async bunker(uri: string): Promise { const login = await NLogin.fromBunker(uri, nostr); addLogin(login); }, // Login via client-initiated NIP-46 ("nostrconnect://" QR code). // Caller generates params with `generateNostrConnectParams`, renders the // URI as a QR/deep-link, and awaits this promise — it resolves when the // remote signer connects back over the relay. async nostrconnect(params: NostrConnectParams, signal?: AbortSignal): Promise { const login = await NLogin.fromNostrConnect(params, nostr, { signal }); addLogin(login); }, // Login with a NIP-07 browser extension async extension(): Promise { const login = await NLogin.fromExtension(); addLogin(login); }, // Log out the current user async logout(): Promise { const login = logins[0]; if (login) { removeLogin(login.id); } } }; }