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!

Clearing dashboard / cache on logout

Blue Mouseb77e481867c0
diff --git a/src/redux/reducers/ui/cache.js b/src/redux/reducers/ui/cache.js
index dfaf6595e..e907c0ad9 100644
--- a/src/redux/reducers/ui/cache.js
+++ b/src/redux/reducers/ui/cache.js
@@ -38,9 +38,16 @@ const cacheReducer = (state = getInitialState(), { type, payload }) => {
const key = getProjectCacheKey(period, timeBucket)
if (_isEmpty(period) || _isEmpty(timeBucket)) {
- return {
- ...state,
- analytics: _filter(state.analytics, (project) => project !== pid),
+ if (_isEmpty(pid)) {
+ return {
+ ...state,
+ analytics: {},
+ }
+ } else {
+ return {
+ ...state,
+ analytics: _filter(state.analytics, (project) => project !== pid),
+ }
}
}
diff --git a/src/redux/sagas/ui/index.js b/src/redux/sagas/ui/index.js
index a5d3c2562..628d757c0 100644
--- a/src/redux/sagas/ui/index.js
+++ b/src/redux/sagas/ui/index.js
@@ -1,12 +1,15 @@
import { takeEvery, fork } from 'redux-saga/effects'
import { types } from '../../actions/ui/types'
+import { types as authTypes } from '../../actions/auth/types'
import loadProjects from './load_projects'
import initialise from './initialise'
+import logout from './logout'
function* mainUISaga() {
yield fork(initialise)
yield takeEvery(types.LOAD_PROJECTS, loadProjects)
+ yield takeEvery(authTypes.LOGOUT, logout)
}
export default mainUISaga
diff --git a/src/redux/sagas/ui/logout.js b/src/redux/sagas/ui/logout.js
new file mode 100644
index 000000000..076e53c87
--- /dev/null
+++ b/src/redux/sagas/ui/logout.js
@@ -0,0 +1,8 @@
+import { put } from 'redux-saga/effects'
+
+import UIActions from 'redux/actions/ui'
+
+export default function* logout() {
+ yield put(UIActions.setProjects([]))
+ yield put(UIActions.deleteProjectCache())
+}