diff --git a/CONTEXT.md b/CONTEXT.md index 49c261c..37c3bcf 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -150,6 +150,30 @@ export function MyComponent() { The `useCurrentUser` hook should be used to ensure that the user is logged in before they are able to publish Nostr events. +### Nostr Login + +Nostr supports several types of logins: + +1. Login with nsec +2. Login with browser extension +3. Login with bunker URI + +Functions to log in with each of these methods are exposed by the `useLoginActions` hook: + +```tsx +function MyComponent() { + const login = useLoginActions(); + + login.nsec(nsec); // login by the user pasting their secret key + login.bunker(uri); // login by the user pasting a bunker URI + login.extension(); // login with a NIP-07 browser extension + + return ( +
{/* ... */}
+ ); +} +``` + ## Development Practices - Uses React Query for data fetching and caching diff --git a/src/hooks/useLoginActions.ts b/src/hooks/useLoginActions.ts index dcfda27..f0d98a9 100644 --- a/src/hooks/useLoginActions.ts +++ b/src/hooks/useLoginActions.ts @@ -5,7 +5,7 @@ import { NLogin, useNostrLogin } from '@nostrify/react/login'; export function useLoginActions() { const { nostr } = useNostr(); - const { addLogin } = useNostrLogin(); + const { logins, addLogin, removeLogin } = useNostrLogin(); return { // Login with a Nostr secret key @@ -23,5 +23,12 @@ export function useLoginActions() { const login = await NLogin.fromExtension(); addLogin(login); }, + // Log out the current user + async logout(): Promise { + const login = logins[0]; + if (login) { + removeLogin(login.id); + } + } }; }