feat: use state based auth instead of store based (#488)

* misc: switch to state for auth

* fix: class based auth not working
This commit is contained in:
Xylight authored and GitHub committed 2025-02-08 13:49:09 -08:00
1 parent 8c6ff77fac
commit 5651ad475d
83 files changed
+395 -469

No files matched your search

+3 -11
View File
@@ -29,7 +29,7 @@
let customHref = (href?: string) => {
if (href?.startsWith('?')) {
const current = pageData.url.searchParams
const current = new URLSearchParams(pageData.url.searchParams)
const newParams = new URLSearchParams(href)
current.delete(newParams.keys().toArray()[0])
@@ -56,11 +56,7 @@
<Button
href={customHref(href?.(cursor?.back ?? page - 1))}
color="ghost"
onclick={() => {
invalidateAll()
if (cursor?.back) onchangecursor?.(cursor.back)
else onchange?.(--page)
}}
onclick={() => invalidateAll()}
title={$t('common.back')}
size="square-md"
rounding="pill"
@@ -91,11 +87,7 @@
<Button
href={customHref(href?.(cursor?.next ?? page + 1))}
color="ghost"
onclick={() => {
invalidateAll()
if (cursor?.next) onchangecursor?.(cursor?.next)
else onchange?.(++page)
}}
onclick={() => invalidateAll()}
title={$t('common.next')}
size="square-md"
rounding="pill"
+7 -7
View File
@@ -77,7 +77,7 @@
style="border-radius: inherit;"
>
<div class="ml-auto"></div>
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<NavButton
href="/admin"
label={$t('nav.admin')}
@@ -92,7 +92,7 @@
{/if}
</NavButton>
{/if}
{#if amModOfAny($profile?.user)}
{#if amModOfAny(profile.data?.user)}
<NavButton
href="/moderation"
label={$t('nav.moderation')}
@@ -124,7 +124,7 @@
/>
{/snippet}
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
<MenuButton link href="/create/post" disabled={!$profile?.jwt}>
<MenuButton link href="/create/post" disabled={!profile.data?.jwt}>
{#snippet prefix()}
<Icon src={PencilSquare} size="16" micro />
{/snippet}
@@ -133,17 +133,17 @@
<MenuButton
link
href="/create/community"
disabled={!$profile?.jwt ||
!$profile?.user ||
disabled={!profile.data?.jwt ||
!profile.data?.user ||
($site?.site_view.local_site.community_creation_admin_only &&
!isAdmin($profile.user))}
!isAdmin(profile.data.user))}
>
{#snippet prefix()}
<Icon src={Newspaper} size="16" micro />
{/snippet}
{$t('nav.create.community')}
</MenuButton>
{#if !$profile?.jwt}
{#if !profile.data?.jwt}
<span class="text-sm mx-4 my-1 py-1">
{$t('nav.create.logingate')}
</span>
+6 -6
View File
@@ -74,14 +74,14 @@
hover:border-primary-900 hover:dark:border-primary-100 active:scale-95 {buttonClass}"
title={$t('profile.profile')}
>
{#if $profile?.user}
{#if profile.data?.user}
<div
class="w-full h-full aspect-square object-cover rounded-full grid place-items-center"
>
<Avatar
url={$profile.user.local_user_view.person.avatar}
url={profile.data.user.local_user_view.person.avatar}
width={36}
alt={$profile.user.local_user_view.person.name}
alt={profile.data.user.local_user_view.person.name}
/>
</div>
{#if $notifications.inbox > 0}
@@ -96,9 +96,9 @@
{/if}
</button>
{/snippet}
{#if $profile?.user}
{#if profile.data?.user}
<UserLink
user={$profile?.user.local_user_view.person}
user={profile.data?.user.local_user_view.person}
showInstance={false}
avatar
avatarSize={24}
@@ -108,7 +108,7 @@
{:else}
<MenuDivider>{$t('nav.menu.label')}</MenuDivider>
{/if}
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton link href="/profile">
{#snippet prefix()}
<Icon src={UserCircle} micro width={16} />
@@ -23,7 +23,6 @@
<Button
href={action.href}
onclick
alignment="left"
color="tertiary"
size="lg"
@@ -229,8 +229,8 @@
$effect(() => {
groups = getGroups(
$resumables,
$profile,
$profileData.profiles,
profile.data,
profileData.profiles,
$themeData,
page.data.contextual?.actions,
)
@@ -92,7 +92,7 @@ export function getGroups(
name: t.get('nav.communities'),
icon: GlobeAlt,
},
...(amModOfAny(profile.user)
...(amModOfAny(profile.data.user)
? [
{
href: '/moderation',
@@ -101,7 +101,7 @@ export function getGroups(
},
]
: []),
...(profile.user && isAdmin(profile.user)
...(profile.data.user && isAdmin(profile.data.user)
? [
{
href: '/admin',
@@ -236,23 +236,23 @@ export function getGroups(
],
},
{
name: t.get('profile.profile'),
actions: profile.jwt
name: t.get('profile.data.profile'),
actions: profile.data.jwt
? [
{
href: '/profile/user',
name: t.get('profile.profile'),
name: t.get('profile.data.profile'),
icon: UserCircle,
},
{
href: '/inbox',
name: t.get('profile.inbox'),
name: t.get('profile.data.inbox'),
icon: Inbox,
shortcut: 'i',
},
{
href: '/saved',
name: t.get('profile.saved'),
name: t.get('profile.data.saved'),
icon: Bookmark,
},
{
@@ -311,7 +311,7 @@ export function getGroups(
icon: p.avatar ?? UserCircle,
detail: p.instance,
handle: async () => {
if (profile.id != p.id) {
if (profile.data.id != p.id) {
await setUserID(p.id)
}
@@ -407,9 +407,9 @@ export function getGroups(
],
},
{
name: t.get('profile.subscribed'),
name: t.get('profile.data.subscribed'),
actions:
profile?.user?.follows.map((f) => ({
profile.data?.user?.follows.map((f) => ({
icon: f.community.icon,
name: f.community.title,
href: `/c/${fullCommunityName(
@@ -25,7 +25,7 @@
animate:flip={{ duration: 500, easing: expoOut }}
>
<div class="flex-none grid group">
{#if $profile && !hasFavorite($profile, follow.id)}
{#if profile && !hasFavorite(profile.data, follow.id)}
<Button
rounding="pill"
size="custom"
@@ -36,7 +36,7 @@
>
<Icon src={Star} size="16" mini />
</Button>
{:else if isFavorites && $profile && hasFavorite($profile, follow.id)}
{:else if isFavorites && profile && hasFavorite(profile.data, follow.id)}
<Button
rounding="pill"
size="custom"
@@ -53,7 +53,7 @@
alt={follow.name}
title={follow.title}
width={28}
class={!isFavorites && $profile && hasFavorite($profile, follow.id)
class={!isFavorites && profile && hasFavorite(profile.data, follow.id)
? ''
: 'group-hover:hidden'}
/>
@@ -23,21 +23,22 @@
alignment="left"
loading={switching}
loaderWidth={20}
selected={$profile?.id == prof.id}
selected={profile.data?.id == prof.id}
onclick={async () => {
switching = true
if ($profile?.id != prof.id) {
if (profile.data?.id != prof.id) {
await setUserID(prof.id)
}
await goto(page.url, {
invalidateAll: true,
})
console.log(page.url)
// await goto(page.url, {
// invalidateAll: true,
// })
switching = false
}}
class="w-full font-normal {$profile?.id == prof.id
class="w-full font-normal {profile.data?.id == prof.id
? '!bg-slate-100 dark:!bg-zinc-900'
: ''}"
>
@@ -46,11 +47,11 @@
profile={prof}
{index}
{guest}
selected={$profile?.id == prof.id}
selected={profile.data?.id == prof.id}
/>
{/snippet}
<span
class="inline-flex flex-col gap-0 {$profile?.id == prof.id
class="inline-flex flex-col gap-0 {profile.data?.id == prof.id
? 'font-semibold'
: ''}"
>
+15 -13
View File
@@ -33,7 +33,7 @@
gap-1 h-fit max-h-screen {clazz}"
{style}
>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<SidebarButton icon={UserCircle} href="/profile">
{#snippet label()}
<span>
@@ -90,7 +90,7 @@
{/snippet}
</SidebarButton>
{/if}
{#if $profileData.profiles.length >= 1}
{#if profileData.profiles.length >= 1}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
<Expandable
@@ -103,13 +103,13 @@
{$t('account.accounts')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profileData.profiles.length}
{profileData.profiles.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
{#each [...$profileData.profiles] as prof, index}
{#each [...profileData.profiles] as prof, index}
<div class="w-full">
<ProfileButton {index} {prof} />
</div>
@@ -120,7 +120,7 @@
</Expandable>
{/if}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{#if $profile?.favorites && $profile?.favorites.length > 0}
{#if profile.data?.favorites && profile.data?.favorites.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.favorites}
@@ -135,18 +135,18 @@
{$t('routes.profile.favorites')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.favorites?.length}
{profile.data.favorites?.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList isFavorites items={$profile.favorites} />
<CommunityList isFavorites items={profile.data.favorites} />
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
{/if}
{#if $profile?.user}
{#if $profile?.user.moderates.length > 0}
{#if profile.data?.user}
{#if profile.data?.user.moderates.length > 0}
<Expandable
class="max-w-full min-w-0 w-full"
bind:open={settings.expand.moderates}
@@ -161,14 +161,14 @@
{$t('routes.profile.moderates')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.user?.moderates.length}
{profile.data.user?.moderates.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList
items={$profile.user.moderates.map((i) => i.community)}
items={profile.data.user.moderates.map((i) => i.community)}
/>
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
@@ -188,13 +188,15 @@
{$t('profile.subscribed')}
{#snippet action()}
<span class="dark:text-white text-black">
{$profile.user?.follows.length}
{profile.data.user?.follows.length}
</span>
{/snippet}
</EndPlaceholder>
</span>
{/snippet}
<CommunityList items={$profile.user.follows.map((i) => i.community)} />
<CommunityList
items={profile.data.user.follows.map((i) => i.community)}
/>
</Expandable>
{/if}
</nav>