From abdfade76514563f15b90049f6c4cfa5f6852eef Mon Sep 17 00:00:00 2001 From: Josh Asplund Date: Fri, 15 Nov 2024 15:13:43 -0600 Subject: [PATCH] fix(auth): can't sign out Fixes #131. Explicitly setting the cookie hostname was causing cookie.remove to fail. I cannot fully test this fix since I cannot test oauth on my machine, but I haven't changed any logic so it should be a quick validation. --- src/lib/components/auth/LoginDialog.svelte | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/lib/components/auth/LoginDialog.svelte b/src/lib/components/auth/LoginDialog.svelte index 7d28b46ae..3767cbdbd 100644 --- a/src/lib/components/auth/LoginDialog.svelte +++ b/src/lib/components/auth/LoginDialog.svelte @@ -24,14 +24,10 @@ if (browser) { let first = true; + userToken.subscribe((token) => { - if (token) { - const oneMonth = new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000); - cookie.set('token', token, { - domain: window.location.hostname, - expires: oneMonth - }); - } else if (!first) { + if (!token && !first) { + // User is logged in but token has been set to null (logging out) client .mutation(LogoutDocument, undefined, { requestPolicy: 'network-only' @@ -41,11 +37,13 @@ .then(() => { cookie.remove('token'); }); - } - - first = false; - - if (token) { + $user = null; + } else if (token) { + const oneMonth = new Date(new Date().getTime() + 30 * 24 * 60 * 60 * 1000); + cookie.set('token', token, { + expires: oneMonth + }); + first = false; client .query(GetMeDocument, {}, { requestPolicy: 'network-only' }) .toPromise() @@ -53,11 +51,9 @@ if (response.error) { console.error(response.error.message); } else if (response.data) { - user.set(response.data.getMe); + $user = response.data.getMe; } }); - } else { - user.set(null); } }); } @@ -116,7 +112,7 @@ autohide: false }); } else { - userToken.set(result.data.session.token); + $userToken = result.data.session.token; modalStore.close(); } })