From 9188ef0dec7f5cdb46427014be8410c1f6c7b81e Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 26 Jan 2024 13:04:20 -0800 Subject: fix: authentication loop for identity --- src/routes/+layout.svelte | 25 ++++++++++++++++++++----- src/stores/identity.ts | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index a9c294c2..a1e9ef4b 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -45,6 +45,13 @@ ? 200 : -200; + $: { + if (data.user !== undefined) + getUserIdentity(data.user).then((h) => { + if ($userIdentity.id === -2) userIdentity.set(h); + }); + } + onMount(async () => { if (browser && localStorage.getItem('redirect')) { window.location.href = localStorage.getItem('redirect') ?? '/'; @@ -53,10 +60,6 @@ } settings.get(); - - if (data.user !== undefined) { - if ($userIdentity.id === -1) userIdentity.set(await getUserIdentity(data.user)); - } }); @@ -98,7 +101,19 @@ {$locale().navigation.logIn} {:else} - + { + userIdentity.set({ + id: -2, + name: '', + avatar: 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png' + }); + + window.location.href = root('/api/authentication/log-out'); + }} + > {$locale().navigation.logOut} {#if data.user} diff --git a/src/stores/identity.ts b/src/stores/identity.ts index 765ce5b2..5229c4cd 100644 --- a/src/stores/identity.ts +++ b/src/stores/identity.ts @@ -4,7 +4,7 @@ import { writable } from 'svelte/store'; const defaultIdentity: UserIdentity = { name: '', - id: -1, + id: -2, avatar: 'https://s4.anilist.co/file/anilistcdn/user/avatar/large/default.png' }; -- cgit v1.2.3