Add LogInSelect step for disambiguating pomade sessions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {uniq} from "@welshman/lib"
|
||||
import {Client} from "@pomade/core"
|
||||
import {loginWithPomade} from "@welshman/app"
|
||||
import {preventDefault} from "@lib/html"
|
||||
@@ -17,6 +18,7 @@
|
||||
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import LogInOTP from "@app/components/LogInOTP.svelte"
|
||||
import LogInSelect from "@app/components/LogInSelect.svelte"
|
||||
import {pushModal, clearModals} from "@app/util/modal"
|
||||
import {setChecked} from "@app/util/notifications"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
@@ -38,7 +40,7 @@
|
||||
try {
|
||||
const {ok, options, messages, clientSecret} = await Client.loginWithPassword(email, password)
|
||||
|
||||
if (!ok) {
|
||||
if (!ok || options.length === 0) {
|
||||
console.error(messages)
|
||||
|
||||
return pushToast({
|
||||
@@ -47,21 +49,25 @@
|
||||
})
|
||||
}
|
||||
|
||||
const [client, peers] = options[0]!
|
||||
const {clientOptions, ...res} = await Client.selectLogin(clientSecret, client, peers)
|
||||
|
||||
if (res.ok && clientOptions) {
|
||||
loginWithPomade(clientOptions.group.group_pk.slice(2), email, clientOptions)
|
||||
deleteOldPomadeSessions()
|
||||
setChecked("*")
|
||||
clearModals()
|
||||
if (uniq(options.map(o => o.pubkey)).length > 1) {
|
||||
pushModal(LogInSelect, {email, options, clientSecret})
|
||||
} else {
|
||||
console.error(res.messages)
|
||||
const {client, peers} = options[0]
|
||||
const {clientOptions, ...res} = await Client.selectLogin(clientSecret, client, peers)
|
||||
|
||||
pushToast({
|
||||
theme: "error",
|
||||
message: "Sorry, we were unable to log you in.",
|
||||
})
|
||||
if (res.ok && clientOptions) {
|
||||
loginWithPomade(clientOptions.group.group_pk.slice(2), email, clientOptions)
|
||||
deleteOldPomadeSessions()
|
||||
setChecked("*")
|
||||
clearModals()
|
||||
} else {
|
||||
console.error(res.messages)
|
||||
|
||||
pushToast({
|
||||
theme: "error",
|
||||
message: "Sorry, we were unable to log you in.",
|
||||
})
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
loading = false
|
||||
|
||||
Reference in New Issue
Block a user