fix: Remove unnecessary cookie setting in LoginPhase and MenuUiHandler

This commit is contained in:
Frederico Santos 2024-07-21 15:55:42 +01:00
parent 4c655691e5
commit 93bcf8ade9
4 changed files with 10 additions and 6 deletions

View File

@ -98,7 +98,7 @@ export class LoginPhase extends Phase {
const loadData = () => {
updateUserInfo().then(success => {
if (!success[0]) {
Utils.setCookie(Utils.sessionIdKey, "");
Utils.removeCookie(Utils.sessionIdKey);
this.scene.reset(true, true);
return;
}
@ -119,7 +119,7 @@ export class LoginPhase extends Phase {
this.scene.ui.playSelect();
updateUserInfo().then(success => {
if (!success[0]) {
Utils.setCookie(Utils.sessionIdKey, "");
Utils.removeCookie(Utils.sessionIdKey);
this.scene.reset(true, true);
return;
}
@ -145,7 +145,7 @@ export class LoginPhase extends Phase {
]
});
} else if (statusCode === 401) {
Utils.setCookie(Utils.sessionIdKey, "");
Utils.removeCookie(Utils.sessionIdKey);
this.scene.reset(true, true);
} else {
this.scene.unshiftPhase(new UnavailablePhase(this.scene));

View File

@ -462,7 +462,7 @@ export default class MenuUiHandler extends MessageUiHandler {
if (!res.ok) {
console.error(`Log out failed (${res.status}: ${res.statusText})`);
}
Utils.setCookie(Utils.sessionIdKey, "");
Utils.removeCookie(Utils.sessionIdKey);
updateUserInfo().then(() => this.scene.reset(true, true));
});
};

View File

@ -58,7 +58,7 @@ export default class UnavailableModalUiHandler extends ModalUiHandler {
this.scene.playSound("pb_bounce_1");
this.reconnectCallback();
} else if (response[1] === 401) {
Utils.setCookie(Utils.sessionIdKey, "");
Utils.removeCookie(Utils.sessionIdKey);
this.scene.reset(true, true);
} else {
this.reconnectDuration = Math.min(this.reconnectDuration * 2, this.maxTime); // Set a max delay so it isn't infinite

View File

@ -297,7 +297,11 @@ export const isBeta = import.meta.env.MODE === "beta"; // this checks to see if
export function setCookie(cName: string, cValue: string): void {
const expiration = new Date();
expiration.setTime(new Date().getTime() + 3600000 * 24 * 30 * 3/*7*/);
document.cookie = `${cName}=${cValue};Secure;SameSite=Strict;Domain=beta.pokerogue.net;Path=/;Expires=${expiration.toUTCString()}`;
document.cookie = `${cName}=${cValue};Secure;SameSite=Strict;Domain=${window.location.hostname};Path=/;Expires=${expiration.toUTCString()}`;
}
export function removeCookie(cName: string): void {
document.cookie = `${cName}=;Secure;SameSite=Strict;Domain=${window.location.hostname};Path=/;Expires=Thu, 01 Jan 1970 00:00:00 GMT`;
}
export function getCookie(cName: string): string {