Fix amber login type: use x-amber instead of amber
NLoginOther requires type x-${string} to be a valid NLoginType.
Using bare 'amber' meant pubkey was never properly stored/rehydrated
from localStorage — it was always undefined/empty.
Using NLogin('x-amber', pubkey, ...) correctly stores pubkey through
the NLoginBase interface and survives localStorage serialization.
Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
This commit is contained in:
parent
dd650ee57c
commit
52bf618b51
2 changed files with 10 additions and 10 deletions
|
|
@ -22,7 +22,7 @@ export function useCurrentUser() {
|
||||||
return NUser.fromBunkerLogin(login, nostr);
|
return NUser.fromBunkerLogin(login, nostr);
|
||||||
case 'extension': // Nostr login with NIP-07 browser extension
|
case 'extension': // Nostr login with NIP-07 browser extension
|
||||||
return NUser.fromExtensionLogin(login);
|
return NUser.fromExtensionLogin(login);
|
||||||
case 'amber': { // Nostr login with Amber (NIP-55)
|
case 'x-amber': { // Nostr login with Amber (NIP-55)
|
||||||
const amberLogin = login as AmberLoginType;
|
const amberLogin = login as AmberLoginType;
|
||||||
// On Capacitor (ZapStore APK) use the native plugin signer so all
|
// On Capacitor (ZapStore APK) use the native plugin signer so all
|
||||||
// signing operations go through Amber via native intents.
|
// signing operations go through Amber via native intents.
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ import {
|
||||||
|
|
||||||
// NOTE: This file should not be edited except for adding new login methods.
|
// NOTE: This file should not be edited except for adding new login methods.
|
||||||
|
|
||||||
export type AmberLoginType = { id: string; type: 'amber'; pubkey: string };
|
// NLoginOther requires type to be `x-${string}` — use x-amber so it
|
||||||
|
// is a valid NLoginType and pubkey is preserved through serialization.
|
||||||
|
export type AmberLoginType = NLoginType & { type: 'x-amber'; pubkey: string };
|
||||||
|
|
||||||
export function useLoginActions() {
|
export function useLoginActions() {
|
||||||
const { nostr } = useNostr();
|
const { nostr } = useNostr();
|
||||||
|
|
@ -34,15 +36,13 @@ export function useLoginActions() {
|
||||||
const login = await NLogin.fromExtension();
|
const login = await NLogin.fromExtension();
|
||||||
addAndActivate(login);
|
addAndActivate(login);
|
||||||
},
|
},
|
||||||
// Login with Amber (NIP-55) — pubkey comes from the AmberCallbackPage
|
// Login with Amber (NIP-55) — pubkey returned from Amber plugin or callback
|
||||||
|
// Uses NLogin with type x-amber so it satisfies NLoginOther (x-${string})
|
||||||
|
// and pubkey is correctly stored and rehydrated from localStorage.
|
||||||
amber(pubkey: string): void {
|
amber(pubkey: string): void {
|
||||||
const amberLogin: AmberLoginType = {
|
const login = new NLogin('x-amber', pubkey, { method: 'nip55' }) as unknown as NLoginType;
|
||||||
id: `amber:${pubkey}`,
|
addLogin(login);
|
||||||
type: 'amber',
|
setLogin(login.id);
|
||||||
pubkey,
|
|
||||||
};
|
|
||||||
addLogin(amberLogin as unknown as NLoginType);
|
|
||||||
setLogin(amberLogin.id);
|
|
||||||
},
|
},
|
||||||
// Log out the current user
|
// Log out the current user
|
||||||
async logout(): Promise<void> {
|
async logout(): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue