import { API_TOKEN, API_TOKEN_KEY } from '@/store/utils/localStorageKeys'
import { setDefaultToken } from '@/store/utils/api'

export default {
  name: 'default',
  type: 'path',
  match: '/',
  inAppArea: async function(app) {
    let token = localStorage.getItem(API_TOKEN)

    if (app && app.$echo) {
      app.$echo.connector.options.auth.headers['Authorization'] = 'Bearer ' + token
    }

    localStorage.setItem(API_TOKEN_KEY, API_TOKEN)
    setDefaultToken(token)
  },
}
