mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2025-08-27 13:09:22 +00:00
Add comments to useLoginActions
This commit is contained in:
parent
3c5e6803b4
commit
e081094cdf
@ -10,14 +10,14 @@ export function useCurrentUser() {
|
|||||||
|
|
||||||
const loginToUser = useCallback((login: NLoginType): NUser => {
|
const loginToUser = useCallback((login: NLoginType): NUser => {
|
||||||
switch (login.type) {
|
switch (login.type) {
|
||||||
case 'nsec':
|
case 'nsec': // Nostr login with secret key
|
||||||
return NUser.fromNsecLogin(login);
|
return NUser.fromNsecLogin(login);
|
||||||
case 'bunker':
|
case 'bunker': // Nostr login with NIP-46 "bunker://" URI
|
||||||
return NUser.fromBunkerLogin(login, nostr);
|
return NUser.fromBunkerLogin(login, nostr);
|
||||||
case 'extension':
|
case 'extension': // Nostr login with NIP-07 browser extension
|
||||||
return NUser.fromExtensionLogin(login);
|
return NUser.fromExtensionLogin(login);
|
||||||
|
// Other login types can be defined here
|
||||||
default:
|
default:
|
||||||
// Learn how to define other login types: https://nostrify.dev/react/logins#custom-login-types
|
|
||||||
throw new Error(`Unsupported login type: ${login.type}`);
|
throw new Error(`Unsupported login type: ${login.type}`);
|
||||||
}
|
}
|
||||||
}, [nostr]);
|
}, [nostr]);
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
import { useNostr } from '@nostrify/react';
|
import { useNostr } from '@nostrify/react';
|
||||||
import { NLogin, useNostrLogin } from '@nostrify/react/login';
|
import { NLogin, useNostrLogin } from '@nostrify/react/login';
|
||||||
|
|
||||||
|
// NOTE: This file should not be edited except for adding new login methods.
|
||||||
|
|
||||||
export function useLoginActions() {
|
export function useLoginActions() {
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
const { addLogin } = useNostrLogin();
|
const { addLogin } = useNostrLogin();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// Login with a Nostr secret key
|
||||||
nsec(nsec: string): void {
|
nsec(nsec: string): void {
|
||||||
const login = NLogin.fromNsec(nsec);
|
const login = NLogin.fromNsec(nsec);
|
||||||
addLogin(login);
|
addLogin(login);
|
||||||
},
|
},
|
||||||
|
// Login with a NIP-46 "bunker://" URI
|
||||||
async bunker(uri: string): Promise<void> {
|
async bunker(uri: string): Promise<void> {
|
||||||
const login = await NLogin.fromBunker(uri, nostr);
|
const login = await NLogin.fromBunker(uri, nostr);
|
||||||
addLogin(login);
|
addLogin(login);
|
||||||
},
|
},
|
||||||
|
// Login with a NIP-07 browser extension
|
||||||
async extension(): Promise<void> {
|
async extension(): Promise<void> {
|
||||||
const login = await NLogin.fromExtension();
|
const login = await NLogin.fromExtension();
|
||||||
addLogin(login);
|
addLogin(login);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user