我使用vue-authenticate ( https://github.com/dgrubelic/vue-authenticate ) 使用 ID/Password 和 Oauth 1 & 2 登录。
我在哪里放置路由器重定向以在仪表板页面上重定向用户?
this.$router.push({name: 'dashboard'})
我的代码 store.js 与 Vuex:
import Vue from 'vue'
import Vuex from 'vuex'
import {vueAuth} from './auth'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
isAuthenticated: false
},
getters: {
isAuthenticated () {
return vueAuth.isAuthenticated()
}
},
mutations: {
isAuthenticated (state, payload) {
state.isAuthenticated = payload.isAuthenticated
},
setProfile (state, payload) {
state.profile = payload.profile
}
},
actions: {
login (context, payload) {
payload = payload || {}
return vueAuth.login(payload.user, payload.requestOptions).then((response) => {
context.commit('isAuthenticated', {
isAuthenticated: vueAuth.isAuthenticated()
})
})
}
}
})