Add LogInSelect step for disambiguating pomade sessions

This commit is contained in:
Jon Staab
2026-03-06 09:23:37 -08:00
parent a45633e214
commit 10ac15f8a2
5 changed files with 135 additions and 41 deletions
+20 -14
View File
@@ -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
+23 -17
View File
@@ -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"
@@ -13,7 +14,8 @@
import ModalTitle from "@lib/components/ModalTitle.svelte"
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import {clearModals} from "@app/util/modal"
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"
import {POMADE_SIGNERS} from "@app/core/state"
@@ -34,10 +36,10 @@
.map(x => x.trim())
.filter(x => x.match(/^[0-9]{8}$/))
if (otps.length < 2) {
if (otps.length < 3) {
return pushToast({
theme: "error",
message: "Failed to recover, not enough valid recovery codes were provided.",
message: "Not enough valid recovery codes were provided.",
})
}
@@ -50,7 +52,7 @@
otps,
)
if (!ok) {
if (!ok || options.length === 0) {
console.error(messages)
return pushToast({
@@ -59,21 +61,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
+82
View File
@@ -0,0 +1,82 @@
<script lang="ts">
import type {AccountOption} from "@pomade/core"
import {Client} from "@pomade/core"
import {loginWithPomade} from "@welshman/app"
import Button from "@lib/components/Button.svelte"
import Spinner from "@lib/components/Spinner.svelte"
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
import ModalHeader from "@lib/components/ModalHeader.svelte"
import ModalTitle from "@lib/components/ModalTitle.svelte"
import ModalSubtitle from "@lib/components/ModalSubtitle.svelte"
import ModalFooter from "@lib/components/ModalFooter.svelte"
import Profile from "@app/components/Profile.svelte"
import {clearModals} from "@app/util/modal"
import {setChecked} from "@app/util/notifications"
import {pushToast} from "@app/util/toast"
import {deleteOldPomadeSessions} from "@app/core/commands"
interface Props {
email: string
options: AccountOption[]
clientSecret: string
}
let {email, options, clientSecret}: Props = $props()
let loading = $state(false)
const back = () => history.back()
const selectAccount = async ({client, peers}: AccountOption) => {
loading = true
try {
const {clientOptions, ...res} = await Client.selectLogin(clientSecret, client, peers)
if (res.ok && clientOptions) {
loginWithPomade(clientOptions.group.group_pk.slice(2), clientOptions.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
}
}
</script>
<Modal>
<ModalBody>
<ModalHeader>
<ModalTitle>Select Account</ModalTitle>
<ModalSubtitle>Multiple accounts are associated with {email}. Please select one to continue.</ModalSubtitle>
</ModalHeader>
<div class="flex flex-col gap-2">
{#each options as option (option.pubkey)}
<Button
onclick={() => selectAccount(option)}
disabled={loading}
class="card2 bg-alt flex w-full items-center p-3 text-left">
<Profile pubkey={option.pubkey} />
</Button>
{/each}
</div>
</ModalBody>
<ModalFooter>
<Button class="btn btn-link" onclick={back} disabled={loading}>
<Icon icon={AltArrowLeft} />
Go back
</Button>
<Spinner {loading} />
</ModalFooter>
</Modal>