The entire nostrconnect relay approach was wrong for a native Android/Capacitor app.
Amber on Android uses NIP-55 intents (nostrsigner: URI scheme), not NIP-46 relays.
New flow (same as Amethyst):
1. openAmberForLogin() fires nostrsigner:?type=get_public_key&callbackUrl=...
2. Amber opens, user taps approve
3. Amber calls back to org.skatespots.app://amber-callback?event=<pubkey>
4. AmberCallbackPage writes pubkey to localStorage('amber_pending_pubkey')
5. LoginDialog polls localStorage every 500ms and calls login.amber(pubkey)
6. Done — no relays, no waiting, no spinning
Also added login.amber(pubkey) method to useLoginActions.
Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import { useNostr } from '@nostrify/react';
|
|
import {
|
|
NLogin,
|
|
type NLoginType,
|
|
useNostrLogin,
|
|
} from '@nostrify/react/login';
|
|
|
|
// NOTE: This file should not be edited except for adding new login methods.
|
|
|
|
export type AmberLoginType = { id: string; type: 'amber'; pubkey: string };
|
|
|
|
export function useLoginActions() {
|
|
const { nostr } = useNostr();
|
|
const { logins, addLogin, setLogin, removeLogin } = useNostrLogin();
|
|
|
|
const addAndActivate = (login: NLoginType) => {
|
|
addLogin(login);
|
|
setLogin(login.id);
|
|
};
|
|
|
|
return {
|
|
// Login with a Nostr secret key
|
|
nsec(nsec: string): void {
|
|
const login = NLogin.fromNsec(nsec);
|
|
addAndActivate(login);
|
|
},
|
|
// Login with a NIP-46 "bunker://" URI
|
|
async bunker(uri: string): Promise<void> {
|
|
const login = await NLogin.fromBunker(uri, nostr);
|
|
addAndActivate(login);
|
|
},
|
|
// Login with a NIP-07 browser extension
|
|
async extension(): Promise<void> {
|
|
const login = await NLogin.fromExtension();
|
|
addAndActivate(login);
|
|
},
|
|
// Login with Amber (NIP-55) — pubkey comes from the AmberCallbackPage
|
|
amber(pubkey: string): void {
|
|
const amberLogin: AmberLoginType = {
|
|
id: `amber:${pubkey}`,
|
|
type: 'amber',
|
|
pubkey,
|
|
};
|
|
addLogin(amberLogin as unknown as NLoginType);
|
|
setLogin(amberLogin.id);
|
|
},
|
|
// Log out the current user
|
|
async logout(): Promise<void> {
|
|
const login = logins[0];
|
|
if (login) {
|
|
removeLogin(login.id);
|
|
}
|
|
},
|
|
};
|
|
}
|