fix: attempt to resolve login bugs
This commit is contained in:
@@ -55,18 +55,9 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
const act = storage.getCurrentAccount() ?? accounts[0] // auto login the first account
|
const act = storage.getCurrentAccount() ?? accounts[0] // auto login the first account
|
||||||
if (!act) return
|
if (!act) return
|
||||||
|
|
||||||
setAccount({ pubkey: act.pubkey, signerType: act.signerType })
|
await loginWithAccountPointer(act)
|
||||||
|
|
||||||
const pubkey = await loginWithAccountPointer(act)
|
|
||||||
// login failed, set account to null
|
|
||||||
if (!pubkey) {
|
|
||||||
setAccount(null)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
init()
|
||||||
init().catch(() => {
|
|
||||||
setAccount(null)
|
|
||||||
})
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const login = (signer: ISigner, act: TAccount) => {
|
const login = (signer: ISigner, act: TAccount) => {
|
||||||
@@ -89,6 +80,7 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
if (!act) {
|
if (!act) {
|
||||||
storage.switchAccount(null)
|
storage.switchAccount(null)
|
||||||
setAccount(null)
|
setAccount(null)
|
||||||
|
setSigner(null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await loginWithAccountPointer(act)
|
await loginWithAccountPointer(act)
|
||||||
@@ -153,16 +145,6 @@ export function NostrProvider({ children }: { children: React.ReactNode }) {
|
|||||||
}
|
}
|
||||||
} else if (account.signerType === 'nip-07') {
|
} else if (account.signerType === 'nip-07') {
|
||||||
const nip07Signer = new Nip07Signer()
|
const nip07Signer = new Nip07Signer()
|
||||||
const pubkey = await nip07Signer.getPublicKey()
|
|
||||||
if (!pubkey) {
|
|
||||||
storage.removeAccount(account)
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
if (pubkey !== account.pubkey) {
|
|
||||||
storage.removeAccount(account)
|
|
||||||
account = { ...account, pubkey }
|
|
||||||
storage.addAccount(account)
|
|
||||||
}
|
|
||||||
return login(nip07Signer, account)
|
return login(nip07Signer, account)
|
||||||
} else if (account.signerType === 'bunker') {
|
} else if (account.signerType === 'bunker') {
|
||||||
if (account.bunker && account.bunkerClientSecretKey) {
|
if (account.bunker && account.bunkerClientSecretKey) {
|
||||||
|
|||||||
Reference in New Issue
Block a user