fix: login

This commit is contained in:
Vlad Stan 2023-07-07 10:53:48 +03:00
parent 602d6858cd
commit 14bb0ff6e6
2 changed files with 20 additions and 34 deletions

View file

@ -135,7 +135,7 @@ const market = async () => {
this.shoppingCarts = this.$q.localStorage.getItem('nostrmarket.shoppingCarts') || []
// Check for user stored
this.account = this.$q.localStorage.getItem('diagonAlley.account') || null
this.account = this.$q.localStorage.getItem('nostrmarket.account') || null
//console.log("UUID", crypto.randomUUID())
// Check for stored merchants and relays on localStorage
@ -209,23 +209,24 @@ const market = async () => {
`This will delete all stored data. If you didn't backup the Key Pair (Private and Public Keys), you will lose it. Continue?`
)
.onOk(() => {
window.localStorage.removeItem('diagonAlley.account')
window.localStorage.removeItem('nostrmarket.account')
this.account = null
})
},
async createAccount(useExtension = false) {
console.log('### createAccount',)
let nip07
if (useExtension) {
await this.getFromExtension()
nip07 = true
}
if (this.isValidKey) {
if (isValidKey(this.accountDialog.data.key, 'nsec')) {
let { key, watchOnly } = this.accountDialog.data
if (key.startsWith('n')) {
let { type, data } = NostrTools.nip19.decode(key)
key = data
}
this.$q.localStorage.set('diagonAlley.account', {
this.$q.localStorage.set('nostrmarket.account', {
privkey: watchOnly ? null : key,
pubkey: watchOnly ? key : NostrTools.getPublicKey(key),
useExtension: nip07 ?? false
@ -235,8 +236,9 @@ const market = async () => {
key: null
}
this.accountDialog.show = false
this.account = this.$q.localStorage.getItem('diagonAlley.account')
this.account = this.$q.localStorage.getItem('nostrmarket.account')
}
this.accountDialog.show = false
},
generateKeyPair() {
this.accountDialog.data.key = NostrTools.generatePrivateKey()
@ -597,7 +599,7 @@ const market = async () => {
const stallCart = this.shoppingCarts.find(c => c.id === item.stallId)
if (stallCart) {
stallCart.products = stallCart.products.filter(p => p.id !== item.productId)
if (!stallCart.products.length){
if (!stallCart.products.length) {
this.shoppingCarts = this.shoppingCarts.filter(s => s.id !== item.stallId)
}
this.$q.localStorage.set('nostrmarket.shoppingCarts', this.shoppingCarts)

View file

@ -224,44 +224,28 @@
</q-page-container>
<!-- ACCOUNT DIALOG -->
<q-dialog v-model="accountDialog.show" persistent>
<q-card style="min-width: 350px">
<q-card-section class="row items-center q-pb-none">
<q-dialog v-model="accountDialog.show" position="top">
<q-card >
<q-card-section class="row">
<div class="text-h6">Account Setup</div>
<q-space></q-space>
<q-btn icon="close" flat round dense v-close-popup></q-btn>
</q-card-section>
<q-card-section>
<p>Type your Nostr private key or generate a new one.</p>
<small> You can also use a Nostr-capable extension. </small>
<p>Enter your Nostr private key or generate a new one.</p>
</q-card-section>
<q-card-section class="q-pt-none">
<q-input dense label="nsec/npub/hex" v-model="accountDialog.data.key" autofocus @keyup.enter="createAccount"
<q-input dense label="Nsec/Hex" v-model="accountDialog.data.key" autofocus @keyup.enter="createAccount"
:error="accountDialog.data.key && !isValidAccountKey"
hint="Enter you private key (recommended) or public key"></q-input>
<q-item tag="label">
<q-item-section avatar top>
<q-checkbox v-model="accountDialog.data.watchOnly"></q-checkbox>
</q-item-section>
<q-item-section>
<q-item-label>Is this a Public Key?</q-item-label>
<q-item-label caption>
If not using an Nostr capable extension, you'll have to sign
events manually! Better to use a Private Key that you can delete
later, or just generate an ephemeral key pair to use in the
Marketplace!
</q-item-label>
</q-item-section>
</q-item>
hint="Enter you private key"></q-input>
</q-card-section>
<q-card-actions align="right" class="text-primary">
<q-btn v-if="hasExtension" flat label="Use Public Key from Extension"
@click="() => createAccount(true)"></q-btn>
<q-btn v-if="isValidAccountKey" label="Add key" color="primary" @click="() => createAccount()"></q-btn>
<q-btn v-if="isValidAccountKey" label="Login" color="primary" @click="() => createAccount()"></q-btn>
<q-btn v-else flat label="Generate" @click="generateKeyPair"></q-btn>
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
>Close</q-btn
>
</q-card-actions>
</q-card>
</q-dialog>