Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

save a token in coockie for working with extensions

kruzhambus45eadf8e4990
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index 4f5376be5..267d54287 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -82,8 +82,6 @@ export const GDPR_EXPORT_TIMEFRAME = 14 // days
export const SHOW_BANNER_AT_PERC = 85 // show banner when 85% of events in tier are used
-export const TOKEN = 'access_token'
-
export const TITLE_SUFFIX = '| Swetrix'
export const LS_THEME_SETTING = 'colour-theme'
@@ -118,6 +116,7 @@ export const getProjectCacheCustomKey = (from, to, timeBucket) => `${from}-${to}
export const GDPR_REQUEST = 'gdpr_request'
export const CONFIRMATION_TIMEOUT = 'confirmation_timeout'
export const LOW_EVENTS_WARNING = 'low_events_warning'
+export const TOKEN = 'access_token'
// List of languages with translations available
export const whitelist = ['en', 'uk', 'de', 'sv', 'el', 'ru', 'hi', 'zh']
diff --git a/src/utils/accessToken.js b/src/utils/accessToken.js
index 6e92ac197..d459df01a 100644
--- a/src/utils/accessToken.js
+++ b/src/utils/accessToken.js
@@ -1,27 +1,15 @@
-import _isEmpty from 'lodash/isEmpty'
import { TOKEN } from 'redux/constants'
-import { getItem, setItem, removeItem } from './localstorage'
+import { setCookie, getCookie } from './cookie'
export const getAccessToken = () => {
- let accessToken = getItem(TOKEN)
-
- if (_isEmpty(accessToken)) {
- accessToken = sessionStorage.getItem(TOKEN)
- }
-
- return accessToken
+ return getCookie(TOKEN)
}
-export const setAccessToken = (token, temporary = false) => {
- if (temporary) {
- sessionStorage.setItem(TOKEN, token)
- return
- }
-
- setItem(TOKEN, token)
+export const setAccessToken = (token) => {
+ setCookie(TOKEN, token)
}
export const removeAccessToken = () => {
- removeItem(TOKEN)
+ setCookie(TOKEN, '', 0)
sessionStorage.removeItem(TOKEN)
}