diff --git a/src/pages/onboarding/create/index.tsx b/src/pages/onboarding/create/index.tsx index f41b53bf..852f7f70 100644 --- a/src/pages/onboarding/create/index.tsx +++ b/src/pages/onboarding/create/index.tsx @@ -54,11 +54,13 @@ export default function Page() { ); // insert to database const insertDB = async () => { - await db.execute( - `INSERT INTO accounts (id, privkey, npub, nsec, metadata) VALUES ("${pubKey}", "${privKey}", "${npub}", "${nsec}", '${JSON.stringify( - data - )}')` - ); + await db.execute('INSERT OR IGNORE INTO accounts (id, privkey, npub, nsec, metadata) VALUES (?, ?, ?, ?, ?)', [ + pubKey, + privKey, + npub, + nsec, + data, + ]); }; // build event and broadcast to all relays const createAccount = () => { diff --git a/src/pages/onboarding/login/step-2.tsx b/src/pages/onboarding/login/step-2.tsx index 22cf302a..dbd0ed64 100644 --- a/src/pages/onboarding/login/step-2.tsx +++ b/src/pages/onboarding/login/step-2.tsx @@ -3,7 +3,7 @@ import BaseLayout from '@layouts/base'; import { DatabaseContext } from '@components/contexts/database'; import { RelayContext } from '@components/contexts/relay'; -import { useLocalStorage } from '@rehooks/local-storage'; +import { useLocalStorage, writeStorage } from '@rehooks/local-storage'; import Image from 'next/image'; import { useRouter } from 'next/router'; import { getPublicKey, nip19 } from 'nostr-tools'; @@ -37,9 +37,15 @@ export default function Page() { const npub = privkey ? nip19.npubEncode(pubkey) : null; const nsec = privkey ? nip19.nsecEncode(privkey) : null; // insert to database - await db.execute( - `INSERT OR IGNORE INTO accounts (id, privkey, npub, nsec, metadata) VALUES ("${pubkey}", "${privkey}", "${npub}", "${nsec}", '${metadata}')` - ); + await db.execute('INSERT OR IGNORE INTO accounts (id, privkey, npub, nsec, metadata) VALUES (?, ?, ?, ?, ?)', [ + pubkey, + privkey, + npub, + nsec, + metadata, + ]); + // write to localstorage + writeStorage('current-user', { id: pubkey, privkey: privkey, npub: npub, nsec: nsec, metadata: metadata }); // update state setProfile(JSON.parse(metadata)); },