import { SET_TOKEN, SET_KEY, SET_UNAME } from './type.js'

export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') || '',
    authkey: null,
    uname: sessionStorage.getItem('uname') || '',
  },
  mutations: {
    [SET_TOKEN](state, token) {
      state.token = token
      localStorage.setItem('token', state.token)
    },
    [SET_KEY](state, authkey) {
      state.authkey = authkey
    },
    [SET_UNAME](state, uname) {
      state.uname = uname
      sessionStorage.setItem('uname', state.uname)
    },
  },
  actions: {
    [SET_TOKEN]({ commit }, token) {
      commit(SET_TOKEN, token)
    },
    [SET_KEY]({ commit }, authkey) {
      commit(SET_KEY, authkey)
    },
    [SET_UNAME]({ commit }, uname) {
      commit(SET_UNAME, uname)
    },
  },
}
