From a9adddc0ce36e790c2736c42e09e457ba6cef7e6 Mon Sep 17 00:00:00 2001 From: kristian Date: Thu, 8 Sep 2022 07:33:46 -0700 Subject: [PATCH] Make auth cookie key more unique to avoid collisions with other apps running on the same server. --- src/utils/Auth.js | 4 ++-- src/utils/defaults.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/Auth.js b/src/utils/Auth.js index df9f3478..d819ac7b 100644 --- a/src/utils/Auth.js +++ b/src/utils/Auth.js @@ -125,7 +125,7 @@ export const login = (username, pass, timeout) => { const now = new Date(); const expiry = new Date(now.setTime(now.getTime() + timeout)).toGMTString(); const userObject = { user: username, hash: sha256(pass).toString().toLowerCase() }; - document.cookie = `authenticationToken=${generateUserToken(userObject)};` + document.cookie = `${cookieKeys.AUTH_TOKEN}=${generateUserToken(userObject)};` + `${timeout > 0 ? `expires=${expiry}` : ''}`; localStorage.setItem(localStorageKeys.USERNAME, username); }; @@ -134,7 +134,7 @@ export const login = (username, pass, timeout) => { * Removed the browsers' cookie, causing user to be logged out */ export const logout = () => { - document.cookie = 'authenticationToken=null'; + document.cookie = `${cookieKeys.AUTH_TOKEN}=null`; localStorage.removeItem(localStorageKeys.USERNAME); }; diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 1055d68b..45aa234f 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -136,7 +136,7 @@ module.exports = { }, /* Key names for cookie identifiers */ cookieKeys: { - AUTH_TOKEN: 'authenticationToken', + AUTH_TOKEN: 'dashyAuthToken', }, /* Key names for session storage identifiers */ sessionStorageKeys: {