Add name saving to login flow
This commit is contained in:
parent
5b57b42111
commit
8aabb45917
@ -53,8 +53,16 @@ export const ModalLogin = () => {
|
||||
const submitHandler = async (values: FormInputType) => {
|
||||
try {
|
||||
let npub = values.username
|
||||
if (!npub.startsWith('npub1') && !npub.includes('@')) {
|
||||
npub += '@' + DOMAIN
|
||||
let name = ''
|
||||
if (!npub.startsWith('npub1')) {
|
||||
name = npub
|
||||
if (!npub.includes('@')) {
|
||||
npub += '@' + DOMAIN
|
||||
} else {
|
||||
const nameDomain = npub.split('@')
|
||||
if (nameDomain[1] === DOMAIN)
|
||||
name = nameDomain[0];
|
||||
}
|
||||
}
|
||||
if (npub.includes('@')) {
|
||||
const npubNip05 = await fetchNip05(npub)
|
||||
@ -63,12 +71,13 @@ export const ModalLogin = () => {
|
||||
}
|
||||
const passphrase = values.password
|
||||
|
||||
console.log('fetch', npub, passphrase)
|
||||
const k: any = await swicCall('fetchKey', npub, passphrase)
|
||||
console.log('fetch', npub, name)
|
||||
const k: any = await swicCall('fetchKey', npub, passphrase, name)
|
||||
notify(`Fetched ${k.npub}`, 'success')
|
||||
cleanUpStates()
|
||||
navigate(`/key/${k.npub}`)
|
||||
} catch (error: any) {
|
||||
console.log("error", error);
|
||||
notify(error?.message || 'Something went wrong!', 'error')
|
||||
}
|
||||
}
|
||||
|
@ -521,7 +521,9 @@ export class NoauthBackend {
|
||||
return generatePrivateKey()
|
||||
}
|
||||
|
||||
public async addKey(name: string, nsec?: string): Promise<KeyInfo> {
|
||||
public async addKey({ name, nsec, existingName }
|
||||
: { name: string, nsec?: string, existingName?: boolean }
|
||||
): Promise<KeyInfo> {
|
||||
|
||||
// lowercase
|
||||
name = name.trim().toLocaleLowerCase()
|
||||
@ -548,9 +550,10 @@ export class NoauthBackend {
|
||||
// assign nip05 before adding the key
|
||||
// FIXME set name to db and if this call to 'send' fails
|
||||
// then retry later
|
||||
console.log("adding key", npub, name)
|
||||
if (name)
|
||||
if (!existingName && name && !name.includes('@')) {
|
||||
console.log("adding key", npub, name)
|
||||
await this.sendNameToServer(npub, name)
|
||||
}
|
||||
|
||||
const sub = await this.swg.registration.pushManager.getSubscription()
|
||||
if (sub) await this.sendSubscriptionToServer(npub, sub)
|
||||
@ -825,13 +828,13 @@ export class NoauthBackend {
|
||||
}
|
||||
|
||||
private async generateKey(name: string) {
|
||||
const k = await this.addKey(name)
|
||||
const k = await this.addKey({ name })
|
||||
this.updateUI()
|
||||
return k
|
||||
}
|
||||
|
||||
private async importKey(name: string, nsec: string) {
|
||||
const k = await this.addKey(name, nsec)
|
||||
const k = await this.addKey({ name, nsec })
|
||||
this.updateUI()
|
||||
return k
|
||||
}
|
||||
@ -851,7 +854,7 @@ export class NoauthBackend {
|
||||
await this.sendKeyToServer(npub, enckey, pwh)
|
||||
}
|
||||
|
||||
private async fetchKey(npub: string, passphrase: string) {
|
||||
private async fetchKey(npub: string, passphrase: string, name: string) {
|
||||
const { type, data: pubkey } = nip19.decode(npub)
|
||||
if (type !== 'npub') throw new Error(`Invalid npub ${npub}`)
|
||||
const { pwh } = await this.keysModule.generatePassKey(
|
||||
@ -870,7 +873,7 @@ export class NoauthBackend {
|
||||
enckey,
|
||||
passphrase,
|
||||
})
|
||||
const k = await this.addKey(nsec)
|
||||
const k = await this.addKey({ name, nsec, existingName: true })
|
||||
this.updateUI()
|
||||
return k
|
||||
}
|
||||
@ -943,7 +946,7 @@ export class NoauthBackend {
|
||||
} else if (method === 'saveKey') {
|
||||
result = await this.saveKey(args[0], args[1])
|
||||
} else if (method === 'fetchKey') {
|
||||
result = await this.fetchKey(args[0], args[1])
|
||||
result = await this.fetchKey(args[0], args[1], args[2])
|
||||
} else if (method === 'confirm') {
|
||||
result = await this.confirm(args[0], args[1], args[2], args[3])
|
||||
} else if (method === 'deleteApp') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user