Store_Vuex init...

This commit is contained in:
최준흠 2022-09-12 16:39:26 +09:00
parent 057c089b94
commit 752af19d16
3 changed files with 3 additions and 4 deletions

View File

@ -15,6 +15,7 @@ const destroyToken = (key) => {
// return jsonwebtoken.decode(getToken(key))
// }
const isAuthenticated = () => {
console.log('isAuthenticated' + getToken())
return !!getToken()
}
const getAuthorizationHeader = (config) => {

View File

@ -63,7 +63,7 @@ router.beforeEach((to, from, next) => {
if (to.matched.some((route) => route.meta.requiredAuth)) {
//2. 로그인 인증 않된 경우
//console.log(store.getters)
//console.log(store.getters['AuthStore/isAuthenticated'])
console.log('Router 인증확인:' + store.getters['AuthStore/isAuthenticated'])
if (!store.getters['AuthStore/isAuthenticated']) {
console.log(from.name + ' => 3. To[' + to.name + '] => 로그인')
next({ name: 'login', params: { return_url: to.name } })

View File

@ -38,13 +38,11 @@ const getters = {
const mutations = {
login: function (state, payload = {}) {
state.tokens = payload.tokens
state.isAuthenticated = true
jwt.saveToken('acccess_token', payload.tokens.access_token)
jwt.saveToken('access_token', payload.tokens.access_token)
jwt.saveToken('refresh_token', payload.tokens.refresh_token)
},
logout: function (state) {
state.tokens = {}
state.isAuthenticated = false
jwt.destroyToken()
}
}