mirror of
https://github.com/styppo/hamstr.git
synced 2024-10-18 05:23:28 +00:00
Prompt for private key if needed
This commit is contained in:
parent
856043bae2
commit
1b5033f3d9
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<q-dialog v-model="app.signInDialog.open" @before-show="updateFragment" @hide="onClose">
|
||||
<q-dialog v-model="app.signInDialog.open" @before-show="updateFragment" @hide="onClose" ref="signInDialog">
|
||||
<div class="sign-in-dialog">
|
||||
<q-btn
|
||||
v-if="showClose"
|
||||
@ -39,14 +39,7 @@
|
||||
|
||||
<SignUpForm v-if="fragment === 'sign-up'" @complete="onComplete" />
|
||||
<SignInForm v-if="fragment === 'sign-in'" @complete="onComplete"/>
|
||||
|
||||
<div v-if="fragment === 'complete'" class="complete">
|
||||
<h3>Signed in as</h3>
|
||||
<p>
|
||||
<UserName v-if="pubkey" :pubkey="pubkey" two-line />
|
||||
</p>
|
||||
<button class="btn btn-primary" v-close-popup>Let's go</button>
|
||||
</div>
|
||||
<SignInForm v-if="fragment === 'private-key'" @complete="onComplete" private-key-only />
|
||||
</div>
|
||||
</q-dialog>
|
||||
</template>
|
||||
@ -54,7 +47,6 @@
|
||||
<script>
|
||||
import Logo from 'components/Logo.vue'
|
||||
import UserAvatar from 'components/User/UserAvatar.vue'
|
||||
import UserName from 'components/User/UserName.vue'
|
||||
import SignUpForm from 'components/SignIn/SignUpForm.vue'
|
||||
import SignInForm from 'components/SignIn/SignInForm.vue'
|
||||
import {useAppStore} from 'stores/App'
|
||||
@ -64,7 +56,6 @@ import Nip07 from 'src/utils/Nip07'
|
||||
export default {
|
||||
name: 'SignInDialog',
|
||||
components: {
|
||||
UserName,
|
||||
Logo,
|
||||
UserAvatar,
|
||||
SignInForm,
|
||||
@ -91,11 +82,10 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
showClose() {
|
||||
return this.fragment === 'welcome'
|
||||
|| (this.fragment !== 'complete' && !this.backAllowed)
|
||||
return this.fragment === 'welcome' || !this.backAllowed
|
||||
},
|
||||
showBack() {
|
||||
return this.fragment !== 'complete' && !this.showClose
|
||||
return !this.showClose
|
||||
},
|
||||
nip07available() {
|
||||
return Nip07.isAvailable()
|
||||
@ -111,7 +101,7 @@ export default {
|
||||
},
|
||||
onComplete({pubkey}) {
|
||||
this.pubkey = pubkey
|
||||
this.fragment = 'complete'
|
||||
this.$refs.signInDialog.hide()
|
||||
},
|
||||
updateFragment() {
|
||||
this.fragment = this.app.signInDialog.fragment || 'welcome'
|
||||
|
@ -1,20 +1,19 @@
|
||||
<template>
|
||||
<div class="sign-in">
|
||||
<h3>Log in</h3>
|
||||
<h3>{{ header }}</h3>
|
||||
<q-form @submit.stop="signIn">
|
||||
<label for="private-key">Paste your public or private key</label>
|
||||
<label for="private-key">{{ prompt }}</label>
|
||||
<input
|
||||
ref="input"
|
||||
v-model="key"
|
||||
id="private-key"
|
||||
placeholder="npub… / nsec…"
|
||||
:placeholder="placeholder"
|
||||
maxlength="63"
|
||||
:class="{
|
||||
valid: validKey,
|
||||
invalid: invalidKey,
|
||||
}"
|
||||
/>
|
||||
<button type="submit" class="btn btn-primary" :disabled="!validKey">Log in</button>
|
||||
<button type="submit" class="btn btn-primary" :disabled="!validKey">{{ buttonLabel }}</button>
|
||||
</q-form>
|
||||
</div>
|
||||
</template>
|
||||
@ -27,12 +26,42 @@ import {useSettingsStore} from 'stores/Settings'
|
||||
export default {
|
||||
name: 'SignInForm',
|
||||
emits: ['complete'],
|
||||
props: {
|
||||
privateKeyOnly: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
key: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
header() {
|
||||
// TODO i18n
|
||||
return this.privateKeyOnly
|
||||
? 'Private key needed'
|
||||
: 'Log in'
|
||||
},
|
||||
prompt() {
|
||||
// TODO i18n
|
||||
return this.privateKeyOnly
|
||||
? 'Paste your private key to continue'
|
||||
: 'Paste your public or private key'
|
||||
},
|
||||
placeholder() {
|
||||
// TODO i18n
|
||||
return this.privateKeyOnly
|
||||
? 'nsec…'
|
||||
: 'npub… / nsec…'
|
||||
},
|
||||
buttonLabel() {
|
||||
// TODO i18n
|
||||
return this.privateKeyOnly
|
||||
? 'Continue'
|
||||
: 'Log in'
|
||||
},
|
||||
validKey() {
|
||||
return this.isValidKey(this.key)
|
||||
},
|
||||
@ -47,7 +76,7 @@ export default {
|
||||
if (!str) return false
|
||||
try {
|
||||
const {data, prefix} = bech32decode(str.toLowerCase())
|
||||
return data.byteLength === 32 && prefix === 'npub' || prefix === 'nsec'
|
||||
return data.byteLength === 32 && ((prefix === 'npub' && !this.privateKeyOnly) || prefix === 'nsec')
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ export class Account {
|
||||
let {sig} = await Nip07.signEvent(event)
|
||||
event.sig = sig
|
||||
} else {
|
||||
// TODO
|
||||
throw new Error('cannot sign')
|
||||
}
|
||||
return event
|
||||
|
@ -42,8 +42,9 @@ export const useAppStore = defineStore('app', {
|
||||
this.createPostDialog.params = options
|
||||
this.createPostDialog.open = true
|
||||
},
|
||||
signEvent(event) {
|
||||
// TODO Check if signing is possible, prompt for privkey
|
||||
async signEvent(event) {
|
||||
if (!await this.signInIfNeeded()) return
|
||||
if (!this.activeAccount.canSign() && !await this.signIn('private-key')) return
|
||||
return this.activeAccount.sign(event)
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user