stage3: add piefed login

This commit is contained in:
James Xylight committed 2025-09-03 21:09:17 -07:00
1 parent d00e8b0d08
commit d236912510
6 files changed
+116 -25

No files matched your search

+51 -8
View File
@@ -3,6 +3,14 @@
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { profile } from '$lib/auth.svelte'
import {
client,
DEFAULT_CLIENT_TYPE,
mayBeIncompatible,
site,
type ClientType,
} from '$lib/client/lemmy.svelte'
import ErrorContainer, {
clearErrorScope,
pushError,
@@ -13,18 +21,16 @@
DEFAULT_INSTANCE_URL,
LINKED_INSTANCE_URL,
} from '$lib/instance.svelte.js'
import { getClient, mayBeIncompatible, site } from '$lib/client/lemmy.svelte'
import { errorMessage } from '$lib/lemmy/error'
import { DOMAIN_REGEX_FORMS } from '$lib/util.svelte.js'
import { MINIMUM_VERSION } from '$lib/version.js'
import { Button, Note, TextInput, toast } from 'mono-svelte'
import { Button, Note, Option, Select, TextInput, toast } from 'mono-svelte'
import {
Icon,
Identification,
QuestionMarkCircle,
UserCircle,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte'
interface Props {
ref?: string
@@ -34,13 +40,22 @@
let { ref = page.url.searchParams.get('redirect') ?? '/', children }: Props =
$props()
let data = $state({
let data = $state<{
instance: string
username: string
password: string
totp: string
loading: boolean
attempts: number
client: ClientType
}>({
instance: DEFAULT_INSTANCE_URL,
username: '',
password: '',
totp: '',
loading: false,
attempts: 0,
client: DEFAULT_CLIENT_TYPE,
})
async function logIn() {
@@ -50,14 +65,22 @@
try {
data.instance = data.instance.trim()
const response = await getClient(data.instance).login({
const response = await client({
instanceURL: data.instance,
clientType: data.client,
auth: '',
}).login({
username_or_email: data.username.trim(),
password: data.password,
totp_2fa_token: data.totp,
})
if (response?.jwt) {
const result = await profile.add(response.jwt, data.instance)
const result = await profile.add(
response.jwt,
data.instance,
data.client,
)
if (result) {
toast({ content: $t('toast.logIn'), type: 'success' })
@@ -120,12 +143,32 @@
placeholder={DEFAULT_INSTANCE_URL}
disabled={LINKED_INSTANCE_URL != undefined}
bind:value={data.instance}
class="flex-1"
class="flex-1 overflow-hidden"
required
pattern={DOMAIN_REGEX_FORMS}
autocorrect="off"
autocapitalize="none"
/>
>
{#snippet suffix()}
<Select
bind:value={
() => {
if (data.client.name == 'lemmy') return 'lemmyv3'
else return 'piefedvalpha'
},
v => {
if (v == 'lemmyv3')
data.client = { name: 'lemmy', baseUrl: '/api/v3' }
else data.client = { name: 'piefed', baseUrl: '/api/alpha' }
}
}
class="border-0 rounded-none! border-l"
>
<Option value="lemmyv3">Lemmy</Option>
<Option value="piefedvalpha">Piefed</Option>
</Select>
{/snippet}
</TextInput>
{/if}
</div>
<div class="flex flex-row gap-2">