import { useNostr } from '@nostrify/react'; import { NLogin, type NLoginType, useNostrLogin, } from '@nostrify/react/login'; // NOTE: This file should not be edited except for adding new login methods. export type AmberLoginType = { id: string; type: 'amber'; pubkey: string }; export function useLoginActions() { const { nostr } = useNostr(); const { logins, addLogin, setLogin, removeLogin } = useNostrLogin(); const addAndActivate = (login: NLoginType) => { addLogin(login); setLogin(login.id); }; return { // Login with a Nostr secret key nsec(nsec: string): void { const login = NLogin.fromNsec(nsec); addAndActivate(login); }, // Login with a NIP-46 "bunker://" URI async bunker(uri: string): Promise { const login = await NLogin.fromBunker(uri, nostr); addAndActivate(login); }, // Login with a NIP-07 browser extension async extension(): Promise { const login = await NLogin.fromExtension(); addAndActivate(login); }, // Login with Amber (NIP-55) — pubkey comes from the AmberCallbackPage amber(pubkey: string): void { const amberLogin: AmberLoginType = { id: `amber:${pubkey}`, type: 'amber', pubkey, }; addLogin(amberLogin as unknown as NLoginType); setLogin(amberLogin.id); }, // Log out the current user async logout(): Promise { const login = logins[0]; if (login) { removeLogin(login.id); } }, }; }