fix: nprofile login

This commit is contained in:
2024-09-09 16:24:55 +01:00
parent b5c8f39446
commit 88a53a0c06

View File

@ -1,5 +1,5 @@
import { fetchNostrAddress, unwrap } from "@snort/shared"; import { fetchNostrAddress, unwrap } from "@snort/shared";
import { KeyStorage, Nip46Signer } from "@snort/system"; import { KeyStorage, Nip46Signer, NostrPrefix, tryParseNostrLink } from "@snort/system";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
import { bech32ToHex } from "@/Utils"; import { bech32ToHex } from "@/Utils";
@ -46,9 +46,12 @@ export default function useLoginHandler() {
} }
// public key logins // public key logins
if (key.startsWith("npub")) { if (key.startsWith("npub") || key.startsWith("nprofile")) {
const hexKey = bech32ToHex(key); const link = tryParseNostrLink(key, NostrPrefix.PublicKey);
LoginStore.loginWithPubkey(hexKey, LoginSessionType.PublicKey); if (!link) {
throw new Error("Invalid public key");
}
LoginStore.loginWithPubkey(link.id, LoginSessionType.PublicKey);
} else if (key.match(EmailRegex)) { } else if (key.match(EmailRegex)) {
const [name, domain] = key.split("@"); const [name, domain] = key.split("@");
const json = await fetchNostrAddress(name, domain); const json = await fetchNostrAddress(name, domain);