store de modules/oauth.js :
import { getToken } from '@/api/oauth'
// mutations
export const SET_ACCESS_TOKEN = 'setAccessToken'
// actions
export const GET_TOKEN = 'getToken'
const state = {
accessToken: null
}
const mutations = {
[SET_ACCESS_TOKEN] (state, payload) {
state.accessToken = payload
}
}
const actions = {
async [GET_TOKEN] ({ commit }) {
try {
const { data } = await getToken()
console.log(data)
} catch (e) {
commit(SET_ACCESS_TOKEN, null)
throw new Error('Error OAuth', e)
} finally {
console.info('Done!')
}
}
}
export default {
namespaced: true,
state,
mutations,
actions
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?