Skip to content

Commit

Permalink
fix(auth): can't sign out
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshuata committed Nov 16, 2024
1 parent 1d65000 commit abdfade
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/lib/components/auth/LoginDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -41,23 +37,23 @@
.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()
.then((response) => {
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);
}
});
}
Expand Down Expand Up @@ -116,7 +112,7 @@
autohide: false
});
} else {
userToken.set(result.data.session.token);
$userToken = result.data.session.token;
modalStore.close();
}
})
Expand Down

0 comments on commit abdfade

Please sign in to comment.