diff --git a/src/store/modules/app.js b/src/store/modules/app.js index 71a973f..e25440f 100644 --- a/src/store/modules/app.js +++ b/src/store/modules/app.js @@ -2,7 +2,18 @@ import Cookies from 'js-cookie' const getDefaultState = () => { - const app = localStorage.getItem('app') && JSON.parse(localStorage.getItem('app')) + + const appData = localStorage.getItem('app') + let app = null + if (appData) { + try { + app = JSON.parse(appData) + } catch (e) { + console.error('Failed to parse app state from localStorage, it might be corrupted:', e) + localStorage.removeItem('app') + } + } + return { sidebar: { opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true, diff --git a/src/store/modules/user.js b/src/store/modules/user.js index a4fbe4b..6c91aa5 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -8,7 +8,16 @@ import Layout from '@/layout' import ParentView from '@/components/ParentView' const getDefaultState = () => { - const store = localStorage.getItem('store') && JSON.parse(localStorage.getItem('store')) + const storeData = localStorage.getItem('store') + let store = null + if (storeData) { + try { + store = JSON.parse(storeData) + } catch (e) { + console.error('Failed to parse user state from localStorage, it might be corrupted:', e) + localStorage.removeItem('store') + } + } return { token: store ? store.token : '', shareToken: store ? store.shareToken : '',