auth: update profile class to contain profileData as well

This commit is contained in:
James Xylight committed 2025-07-12 10:56:38 -07:00
1 parent 36a9631707
commit 185cc5f54d
13 files changed
+238 -265

No files matched your search

+19 -27
View File
@@ -1,13 +1,5 @@
<script lang="ts">
import {
profile as currentProfile,
deleteProfile,
moveProfile,
type Profile,
profile,
profileData,
setUserID,
} from '$lib/auth.svelte.js'
import { profile, type ProfileInfo } from '$lib/auth.svelte.js'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import DebugObject from '$lib/components/util/debug/DebugObject.svelte'
import { t } from '$lib/i18n/translations'
@@ -29,11 +21,11 @@
} from 'svelte-hero-icons'
let debugging = $state(false)
let debugProfile: Profile | undefined = $state(undefined)
let debugProfile: ProfileInfo | undefined = $state(undefined)
let removing = $state({
shown: false,
account: undefined as Profile | undefined,
account: undefined as ProfileInfo | undefined,
})
let switching = $state(-1)
@@ -41,7 +33,7 @@
let radioSelected = $state(profile.current.id)
$effect(() => {
switching = radioSelected
setUserID(radioSelected)
profile.meta.profile = radioSelected
})
$effect(() => {
@@ -94,7 +86,7 @@
<Button
onclick={() => {
removing.shown = false
if (removing.account) deleteProfile(removing.account.id)
if (removing.account) profile.remove(removing.account.id)
}}
size="lg"
class="flex-1"
@@ -141,13 +133,13 @@
{/snippet}
</Header>
<form class="accounts-grid mt-4 sm:mt-6 gap-4">
{#each profileData.profiles as profile, index (profile.id)}
{#each profile.meta.profiles as p, index (p.id)}
<label>
<input
type="radio"
id={profile.id.toString()}
id={p.id.toString()}
name="profile"
value={profile.id}
value={p.id}
class="hidden peer"
bind:group={radioSelected}
/>
@@ -158,26 +150,26 @@
class={[
'flex flex-row items-center px-3 py-3 gap-2 transition-all duration-75 cursor-pointer relative',
'peer-checked:ring-2',
switching == profile.id && 'ring-slate-400 dark:ring-zinc-600',
switching == p.id && 'ring-slate-400 dark:ring-zinc-600',
]}
>
<ProfileAvatar
{profile}
profile={p}
{index}
selected={currentProfile?.data.id == profile.id}
selected={profile?.current.id == p.id}
size={40}
/>
<div class="flex flex-col overflow-hidden">
<span class="break-words font-medium text-base">
{profile.username}
{#if !profile.jwt}
{p.username}
{#if !p.jwt}
<Badge class="inline-grid w-6 h-6 p-0! place-items-center">
<Icon src={QuestionMarkCircle} size="16" micro />
</Badge>
{/if}
</span>
<span class="text-sm text-slate-600 dark:text-zinc-400">
{profile.instance}
{p.instance}
</span>
</div>
<Menu placement="bottom-end">
@@ -203,7 +195,7 @@
size="square-md"
color="secondary"
title={$t('account.moveUp')}
onclick={() => moveProfile(profile.id, true)}
onclick={() => profile.move(p.id, true)}
>
{#snippet prefix()}
<Icon src={ChevronUp} size="16" mini />
@@ -213,7 +205,7 @@
size="square-md"
color="secondary"
title={$t('account.moveDown')}
onclick={() => moveProfile(profile.id, false)}
onclick={() => profile.move(p.id, false)}
>
{#snippet prefix()}
<Icon src={ChevronDown} size="16" mini />
@@ -223,7 +215,7 @@
{#if settings.debugInfo}
<MenuButton
onclick={() => {
debugProfile = profile
debugProfile = p
debugging = !debugging
}}
>
@@ -233,10 +225,10 @@
{$t('common.debug')}
</MenuButton>
{/if}
{#if !LINKED_INSTANCE_URL || profile.user}
{#if !LINKED_INSTANCE_URL || p.user}
<MenuButton
onclick={() => {
removing.account = profile
removing.account = p
removing.shown = !removing.shown
}}
color="danger-subtle"
@@ -2,7 +2,7 @@
import { goto } from '$app/navigation'
import { resolveRoute } from '$app/paths'
import { page } from '$app/state'
import { profile, profileData } from '$lib/auth.svelte'
import { profile } from '$lib/auth.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
@@ -74,8 +74,8 @@
{$t('routes.postRedirect.actions.back')}
</Button>
</div>
{#if profileData.profiles}
{@const filtered = profileData.profiles.filter(
{#if profile.meta.profiles}
{@const filtered = profile.meta.profiles.filter(
i => i.instance == page.params.instance,
)}
<div class="space-y-1">
+2 -2
View File
@@ -3,7 +3,6 @@
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { setUser } from '$lib/auth.svelte.js'
import ErrorContainer, {
clearErrorScope,
pushError,
@@ -25,6 +24,7 @@
QuestionMarkCircle,
UserCircle,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte'
interface Props {
ref?: string
@@ -57,7 +57,7 @@
})
if (response?.jwt) {
const result = await setUser(response.jwt, data.instance, data.username)
const result = await profile.add(response.jwt, data.instance)
if (result) {
toast({ content: $t('toast.logIn'), type: 'success' })
+5 -5
View File
@@ -3,7 +3,6 @@
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { profileData } from '$lib/auth.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
@@ -12,6 +11,7 @@
import { DOMAIN_REGEX_FORMS } from '$lib/util.svelte'
import { MINIMUM_VERSION } from '$lib/version'
import { Button, Note, TextInput, toast } from 'mono-svelte'
import { profile } from '$lib/auth.svelte'
interface Props {
ref?: string
@@ -23,7 +23,7 @@
let form = $state({
instance: '',
username: `${$t('account.guest')} ${profileData.profiles.filter(p => p.jwt == undefined).length + 1}`,
username: `${$t('account.guest')} ${profile.meta.profiles.filter(p => p.jwt == undefined).length + 1}`,
loading: false,
})
@@ -35,13 +35,13 @@
return
}
const id = Math.max(...profileData.profiles.map(i => i.id)) + 1
profileData.profiles.push({
const id = Math.max(...profile.meta.profiles.map(i => i.id)) + 1
profile.meta.profiles.push({
id: id,
instance: form.instance,
username: form.username,
})
profileData.profile = id
profile.meta.profile = id
toast({ content: $t('toast.addAccount'), type: 'success' })
@@ -2,7 +2,7 @@
import { goto } from '$app/navigation'
import { resolveRoute } from '$app/paths'
import { page } from '$app/state'
import { profile, profileData } from '$lib/auth.svelte'
import { profile } from '$lib/auth.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import ProfileButton from '$lib/components/ui/sidebar/ProfileButton.svelte'
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
@@ -74,8 +74,8 @@
{$t('routes.postRedirect.actions.back')}
</Button>
</div>
{#if profileData.profiles}
{@const filtered = profileData.profiles.filter(
{#if profile.meta.profiles}
{@const filtered = profile.meta.profiles.filter(
i => i.instance == page.params.instance,
)}
<div class="space-y-1">
@@ -1,11 +1,11 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { deleteProfile, profile, setUser } from '$lib/auth.svelte'
import { client } from '$lib/lemmy.svelte'
import { t } from '$lib/i18n/translations'
import { Button, TextInput, toast } from 'mono-svelte'
import { errorMessage } from '$lib/lemmy/error'
import { profile } from '$lib/auth.svelte'
let oldPassword = $state(''),
newPassword = $state(''),
@@ -21,9 +21,9 @@
old_password: oldPassword,
})
if (res?.jwt) {
const { instance, username } = profile.current
deleteProfile(profile.current.id)
await setUser(res.jwt, instance, username!)
const { instance } = profile.current
profile.remove(profile.current.id)
await profile.add(res.jwt, instance)
toast({ content: $t('toast.loginRefresh'), type: 'success' })
} else {
@@ -1,6 +1,5 @@
<script lang="ts">
import { goto } from '$app/navigation'
import { profileData, setUserID } from '$lib/auth.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { client } from '$lib/lemmy.svelte'
import { t } from '$lib/i18n/translations'
@@ -14,6 +13,7 @@
TextInput,
toast,
} from 'mono-svelte'
import { profile } from '$lib/auth.svelte'
let deletion = $state({
modal: false,
@@ -70,11 +70,11 @@
delete_content: deletion.deleteContent,
})
profileData.profiles.splice(
profileData.profiles.findIndex(p => profileData.profile == p.id),
profile.meta.profiles.splice(
profile.meta.profiles.findIndex(p => profile.meta.profile == p.id),
)
setUserID(-1)
profile.meta.profile = -1
toast({
content: $t('toast.deleted'),
})
+3 -3
View File
@@ -3,7 +3,6 @@
import { goto } from '$app/navigation'
import { page } from '$app/state'
import { setUser } from '$lib/auth.svelte.js'
import ErrorContainer, {
clearErrorScope,
pushError,
@@ -37,6 +36,7 @@
QuestionMarkCircle,
XCircle,
} from 'svelte-hero-icons'
import { profile } from '$lib/auth.svelte.js'
let { data } = $props()
@@ -88,7 +88,7 @@
const registrationMode = data.site_view.local_site.registration_mode
if (res?.jwt) {
await setUser(res.jwt, page.params.instance)
await profile.add(res.jwt, page.params.instance)
toast({ content: $t('toast.logIn'), type: 'success' })
goto('/')
@@ -127,7 +127,7 @@
})
if (res.jwt) {
await setUser(res.jwt, page.params.instance)
await profile.add(res.jwt, page.params.instance)
goto('/')
} else if (res.verify_email_sent) {
pushError({