mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Adds the client-initiated NIP-46 flow alongside the existing bunker:// paste input. Desktop users scan a generated QR code with their signer app (Amber, nsec.app, etc.); mobile users get an "Open signer app" deep-link plus a /remoteloginsuccess callback page. The pasted bunker:// URI moves into a collapsible fallback below the QR. A shared BunkerLoginPanel component owns the session lifecycle and is embedded in both LoginDialog and SimpleLoginDialog. The listener effect depends only on a sessionToken and reads login/onLoggedIn/config through refs so parent re-renders don't tear down an in-flight handshake. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
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<void> {
|
|
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<void> {
|
|
const login = await NLogin.fromNostrConnect(params, nostr, { signal });
|
|
addLogin(login);
|
|
},
|
|
// Login with a NIP-07 browser extension
|
|
async extension(): Promise<void> {
|
|
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);
|
|
}
|
|
}
|
|
};
|
|
}
|