text: import {getLocalStorage, setLocalStorage} from '@/utils/cache'
  
  export default {
    namespaced: true,
    state: {
      user: undefined,
      permissions: null,
      roles: null,
      routesConfig: null
    },
    getters: {
      user: state => {
        if (!state.user) {
          try {
            const user = getLocalStorage(process.env.VUE_APP_USER_KEY)
            state.user = JSON.parse(user)
          } catch (e) {
            console.error(e)
          }
        }
        return state.user
      },
      permissions: state => {
        if (!state.permissions) {
          try {
            const permissions = getLocalStorage(process.env.VUE_APP_PERMISSIONS_KEY)
            state.permissions = JSON.parse(permissions)
            state.permissions = state.permissions ? state.permissions : []
          } catch (e) {
            console.error(e.message)
          }
        }
        return state.permissions
      },
      roles: state => {
        if (!state.roles) {
          try {
            const roles = getLocalStorage(process.env.VUE_APP_ROLES_KEY)
            state.roles = JSON.parse(roles)
            state.roles = state.roles ? state.roles : []
          } catch (e) {
            console.error(e.message)
          }
        }
        return state.roles
      },
      routesConfig: state => {
        if (!state.routesConfig) {
          try {
            const routesConfig = getLocalStorage(process.env.VUE_APP_ROUTES_KEY)
            state.routesConfig = JSON.parse(routesConfig)
            state.routesConfig = state.routesConfig ? state.routesConfig : []
          } catch (e) {
            console.error(e.message)
          }
        }
        return state.routesConfig
      }
    },
    mutations: {
      setUser (state, user) {
        state.user = user
        setLocalStorage(process.env.VUE_APP_USER_KEY, JSON.stringify(user))
      },
      setPermissions(state, permissions) {
        state.permissions = permissions
        setLocalStorage(process.env.VUE_APP_PERMISSIONS_KEY, JSON.stringify(permissions))
      },
      setRoles(state, roles) {
        state.roles = roles
        setLocalStorage(process.env.VUE_APP_ROLES_KEY, JSON.stringify(roles))
      },
      setRoutesConfig(state, routesConfig) {
        state.routesConfig = routesConfig
        setLocalStorage(process.env.VUE_APP_ROUTES_KEY, JSON.stringify(routesConfig))
      }
    }
  }
  