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

@@ -43,7 +43,7 @@
})
async function submit() {
if (!item || !$profile?.user || !$profile?.jwt) return
if (!item || !profile.data?.user || !profile.data?.jwt) return
loading = true
@@ -33,9 +33,9 @@
<ShieldIcon filled width={14} />
</Button>
{/snippet}
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
<MenuDivider>
{#if !item.community.local && !amMod($profile.user, item.community)}
{#if !item.community.local && !amMod(profile.data.user, item.community)}
{$t('moderation.labelInstanceOnly')}
{:else}
{$t('moderation.label')}
@@ -53,7 +53,7 @@
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
{/if}
</MenuButton>
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
{#if profile.data?.user && profile.data.user?.local_user_view.person.id != item.creator.id}
<!--Comment made by someone else-->
<MenuButton
color="danger-subtle"
@@ -72,12 +72,12 @@
<MenuButton
color="success-subtle"
onclick={async () => {
if (!$profile.jwt) return
if (!profile.data.jwt) return
item.comment = (
await feature(
!item.comment.distinguished,
item.comment,
$profile.jwt,
profile.data.jwt,
)
).comment_view.comment
}}
@@ -92,7 +92,7 @@
{/if}
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuDivider>{$t('admin.label')}</MenuDivider>
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
{#snippet prefix()}
@@ -31,7 +31,7 @@
let acting = $derived(locking || pinning)
async function lock(lock: boolean) {
if (!$profile?.jwt || !isPostView(item)) return
if (!profile.data?.jwt || !isPostView(item)) return
locking = true
try {
@@ -52,7 +52,7 @@
}
async function pin(pinned: boolean, toInstance: boolean = false) {
if (!$profile?.jwt || !isPostView(item)) return
if (!profile.data?.jwt || !isPostView(item)) return
pinning = true
@@ -87,9 +87,9 @@
<ShieldIcon filled width={16} />
</Button>
{/snippet}
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user))}
{#if (profile.data?.user && amMod(profile.data.user, item.community)) || (profile.data?.user && isAdmin(profile.data.user))}
<MenuDivider>
{#if !item.community.local && !amMod($profile.user, item.community)}
{#if !item.community.local && !amMod(profile.data.user, item.community)}
{$t('moderation.labelInstanceOnly')}
{:else}
{$t('moderation.label')}
@@ -123,7 +123,7 @@
? $t('moderation.unfeature')
: $t('moderation.feature')}
</span>
{#if isAdmin($profile.user)}
{#if isAdmin(profile.data.user)}
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
{/if}
</div>
@@ -138,7 +138,7 @@
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
{/if}
</MenuButton>
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
{#if profile.data?.user && profile.data.user.local_user_view.person.id != item.creator.id}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -151,7 +151,7 @@
</MenuButton>
{/if}
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuDivider>{$t('admin.label')}</MenuDivider>
<MenuButton
color="success-subtle"
@@ -66,7 +66,7 @@
async function remove() {
if (!item) return
if (!$profile?.jwt) throw new Error('Unauthenticated')
if (!profile.data?.jwt) throw new Error('Unauthenticated')
loading = true
@@ -207,7 +207,7 @@
bind:value={reason}
/>
{#if !removed && $profile?.user && (amMod($profile.user, item.community) || (isAdmin($profile.user) && item.community.local))}
{#if !removed && profile.data?.user && (amMod(profile.data.user, item.community) || (isAdmin(profile.data.user) && item.community.local))}
<Switch bind:checked={commentReason}>
{$t('moderation.removeSubmission.withReason')}
</Switch>
@@ -41,7 +41,7 @@
let reason = $state('')
async function report() {
if (!item || !$profile?.jwt || reason == '') return
if (!item || !profile.data?.jwt || reason == '') return
loading = true
try {