fix login with Extension, formatting

This commit is contained in:
@s.roertgen 2025-05-06 08:32:52 +02:00
parent 1878d82fad
commit 590e69c1f4

View file

@ -1,33 +1,35 @@
import { NDKNip07Signer, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk"; import { NDKNip07Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
import { ndk } from "$lib/stores"; import { ndk } from '$lib/stores';
import { get } from "svelte/store"; import { get } from 'svelte/store';
export async function login() { export async function login() {
if (window.nostr) { if (window.nostr) {
const signer = new NDKNip07Signer(); const signer = new NDKNip07Signer();
get(ndk).signer = signer; ndk.update((ndk) => {
signer.user(); ndk.signer = signer;
} else { return ndk;
console.log("no extension") });
const storedPrivateKey = window.localStorage.getItem('nostrPrivateKey'); signer.user();
if (storedPrivateKey) { } else {
const privateKey = JSON.parse(storedPrivateKey); console.log('no extension');
console.log("stored private key", privateKey) const storedPrivateKey = window.localStorage.getItem('nostrPrivateKey');
const signer = new NDKPrivateKeySigner(privateKey); if (storedPrivateKey) {
ndk.update((ndk) => { const privateKey = JSON.parse(storedPrivateKey);
ndk.signer = signer; console.log('stored private key', privateKey);
return ndk; const signer = new NDKPrivateKeySigner(privateKey);
}); ndk.update((ndk) => {
// get(ndk).signer = signer; ndk.signer = signer;
signer.user(); return ndk;
} else { });
console.log('No private key found, generating a new one...'); signer.user();
const privateKey = NDKPrivateKeySigner.generate(); } else {
const signer = new NDKPrivateKeySigner(privateKey.privateKey); console.log('No private key found, generating a new one...');
console.log('Generated Private Key:', privateKey); const privateKey = NDKPrivateKeySigner.generate();
signer.user(); const signer = new NDKPrivateKeySigner(privateKey.privateKey);
window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey)); console.log('Generated Private Key:', privateKey);
get(ndk).signer = signer; signer.user();
} window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey));
} get(ndk).signer = signer;
}
}
} }