Skip to content

Commit 82ff4e4

Browse files
authored
Fix bugs causing 403s after refreshing jwt (#2395)
## Description: Two bugs where causing 403s when trying to connect to a game after refreshing the jwt: 1. __isLoggedIn was not cleared, so the existing, cached, token was used. 2. set "credentials: "include" in the refresh request so we get the token as a cookie. getToken() checks cookie before checking "token" in localstorage. So cookie wasn't being updated and we were using the existing cookie. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: evan
1 parent a0c4a2a commit 82ff4e4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/client/jwt.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ export async function postRefresh(): Promise<boolean> {
225225
// Refresh the JWT
226226
const response = await fetch(getApiBase() + "/refresh", {
227227
method: "POST",
228+
credentials: "include",
228229
headers: {
229230
authorization: `Bearer ${token}`,
230231
},
@@ -242,6 +243,9 @@ export async function postRefresh(): Promise<boolean> {
242243
return false;
243244
}
244245
localStorage.setItem("token", result.data.token);
246+
// Clear the cached logged in state
247+
// so that the next call to isLoggedIn() will refresh the token
248+
__isLoggedIn = undefined;
245249
return true;
246250
} catch (e) {
247251
__isLoggedIn = false;

0 commit comments

Comments
 (0)