Skip to content

Commit

Permalink
feat: differ staging cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
zamitto committed Dec 9, 2024
1 parent 45f2727 commit d8b59ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/renderer/src/cookies.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
export function addCookieInterceptor() {
export function addCookieInterceptor(isStaging: boolean) {
const cookieKey = isStaging ? "cookies-staging" : "cookies";

Object.defineProperty(document, "cookie", {
enumerable: true,
configurable: true,
get() {
return localStorage.getItem("cookies") || "";
return localStorage.getItem(cookieKey) || "";
},
set(cookieString) {
try {
const [cookieName, cookieValue] = cookieString.split(";")[0].split("=");

const currentCookies = localStorage.getItem("cookies") || "";
const currentCookies = localStorage.getItem(cookieKey) || "";

const cookiesObject = parseCookieStringsToObjects(currentCookies);
cookiesObject[cookieName] = cookieValue;
Expand All @@ -20,7 +22,7 @@ export function addCookieInterceptor() {
})
.join("; ");

localStorage.setItem("cookies", newString);
localStorage.setItem(cookieKey, newString);
} catch (err) {
console.error(err);
}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const Achievements = React.lazy(

console.log = logger.log;

addCookieInterceptor();
const isStaging = await window.electron.isStaging();
addCookieInterceptor(isStaging);

i18n
.use(LanguageDetector)
Expand Down

0 comments on commit d8b59ca

Please sign in to comment.