mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-26 20:49:22 +00:00
Add Nostr login info to context
This commit is contained in:
parent
b8175a459e
commit
9a95cbe5ce
24
CONTEXT.md
24
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 (
|
||||
<div>{/* ... */}</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Development Practices
|
||||
|
||||
- Uses React Query for data fetching and caching
|
||||
|
@ -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<void> {
|
||||
const login = logins[0];
|
||||
if (login) {
|
||||
removeLogin(login.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user