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

@@ -117,7 +117,7 @@
})
async function subscribe() {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
loading.subscribing = true
const subscribed =
community_view.subscribed == 'Subscribed' ||
@@ -226,7 +226,7 @@
<div
class="flex flex-row items-center gap-1 sticky bottom-0 drop-shadow-xl w-full"
>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<Button
disabled={loading.subscribing}
loading={loading.subscribing}
@@ -250,7 +250,7 @@
: $t('cards.community.subscribe')}
</Button>
{/if}
{#if $profile?.user && amMod($profile.user, community_view.community)}
{#if profile.data?.user && amMod(profile.data.user, community_view.community)}
<Button
href="/c/{fullCommunityName(
community_view.community.name,
@@ -275,7 +275,7 @@
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
color="danger-subtle"
size="lg"
@@ -289,7 +289,7 @@
? $t('cards.community.unblock')
: $t('cards.community.block')}
</MenuButton>
{#if $profile?.user}
{#if profile.data?.user}
<MenuButton
color="danger-subtle"
size="lg"
@@ -301,7 +301,7 @@
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -59,7 +59,7 @@
let formData = $state(passedFormData)
async function submit() {
if (!$profile?.jwt) return
if (!profile.data?.jwt) return
if ((!edit && formData.name == '') || formData.displayName == '') return
formData.submitting = true
@@ -94,23 +94,23 @@
type: 'success',
})
if ($profile.user) {
const c = $profile.user.moderates
if (profile.data.user) {
const c = profile.data.user.moderates
.map((m) => m.community.id)
.indexOf(res.community_view.community.id)
if (c != -1) {
$profile.user.moderates[c] = {
profile.data.user.moderates[c] = {
community: res.community_view.community,
moderator: $profile.user.local_user_view.person,
moderator: profile.data.user.local_user_view.person,
}
} else {
$profile.user = {
...$profile.user,
profile.data.user = {
...profile.data.user,
moderates: [
...$profile.user.moderates,
...profile.data.user.moderates,
{
community: res.community_view.community,
moderator: $profile.user.local_user_view.person,
moderator: profile.data.user.local_user_view.person,
},
],
}
@@ -159,7 +159,7 @@
/>
<TextInput
required
label={$t('form.profile.displayName')}
label={$t('form.profile.data.displayName')}
bind:value={formData.displayName}
/>
<div class="flex flex-row gap-4 flex-wrap *:flex-1">
@@ -236,7 +236,7 @@
</Select>
<div class="space-y-1">
<SectionTitle>{$t('form.profile.languages.title')}</SectionTitle>
<SectionTitle>{$t('form.profile.data.languages.title')}</SectionTitle>
<Material rounding="xl" color="uniform" class="dark:bg-zinc-950">
{#if $site}
<div class="flex gap-2 flex-wrap flex-row">
@@ -112,7 +112,7 @@
</Expandable>
{/if}
<div class="flex items-center gap-2 h-max w-max">
{#if $profile?.jwt}
{#if profile.data?.jwt}
<Subscribe
community={{
community: community,
@@ -151,7 +151,7 @@
</Subscribe>
{/if}
{#if $profile?.user && $profile.user.moderates
{#if profile.data?.user && profile.data.user.moderates
.map((c) => c.community.id)
.includes(community.id)}
<Button
@@ -179,7 +179,7 @@
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
</MenuButton>
{#if $profile?.jwt}
{#if profile.data?.jwt}
<MenuButton
color="danger-subtle"
size="lg"
@@ -192,7 +192,7 @@
? $t('cards.community.unblock')
: $t('cards.community.block')}
</MenuButton>
{#if $profile?.user}
{#if profile.data?.user}
<MenuButton
color="danger-subtle"
size="lg"
@@ -204,7 +204,7 @@
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
{#if $profile?.user && isAdmin($profile.user)}
{#if profile.data?.user && isAdmin(profile.data.user)}
<MenuButton
color="danger-subtle"
onclick={() =>
@@ -104,7 +104,7 @@
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing || !$profile?.jwt}
disabled={subscribing || !profile.data?.jwt}
loading={subscribing}
onclick={async () => {
const res = await subscribe()