{"size": 813, "ext": "js", "max_stars_repo_path": "store/index.js", "max_stars_repo_name": "Yocss/nuxt-template", "max_stars_repo_stars_event_min_datetime": "2020-10-12T01:57:26.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-12T02:02:26.000Z", "max_issues_repo_path": "store/index.js", "max_issues_repo_name": "Yocss/nuxt-template", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "store/index.js", "max_forks_repo_name": "Yocss/nuxt-template", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.1, "max_line_length": 73, "alphanum_fraction": 0.5977859779}
import helper from '@axmine/helper'
import config from '@/config/index.js'
import { getHeaderCookie } from '@/assets/js/common.js'
const keys = config.keys
export const actions = {
  nuxtServerInit ({ state }, { req }) {
    if (!state.token) {
      const token = getHeaderCookie(req.headers.cookie)[keys.token] || ''
      this.dispatch('SetToken', token)
    }
  },

  // setStore
  SetStore ({ commit }, data) {
    commit('SET_STORE', data)
  },
  SetToken ({ commit }, token) {
    if (helper.getType(token) !== 'string') {
      throw new Error('token 必须是一个字符串')
    }
    if (process.client) {
      token ? helper.store.set(keys.token, token, {
        expireDays: 0,
        type: 'cookie'
      }) : helper.store.remove(keys.token, 'cookie')
    }
    commit('SET_STORE', { token: token || '' })
  }
}
