From 9188ef0dec7f5cdb46427014be8410c1f6c7b81e Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Fri, 26 Jan 2024 13:04:20 -0800
Subject: fix: authentication loop for identity

---
 src/routes/+layout.svelte | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

(limited to 'src/routes/+layout.svelte')

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));
-		}
 	});
 </script>
 
@@ -98,7 +101,19 @@
 					{$locale().navigation.logIn}
 				</a>
 			{:else}
-				<a href={root('/api/authentication/log-out')} class="header-item">
+				<a
+					href={'#'}
+					class="header-item"
+					on:click={() => {
+						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}
 				</a>
 				{#if data.user}
-- 
cgit v1.2.3

