Store_Vuex init...
This commit is contained in:
parent
404f44cf85
commit
b869515983
@ -1,17 +1,16 @@
|
||||
//import VueCookies from 'vue-cookies'
|
||||
//import jsonwebtoken from 'jsonwebtoken'
|
||||
import VueCookies from 'vue-cookies'
|
||||
|
||||
const getToken = (key) => {
|
||||
//return VueCookies.get(key)
|
||||
return window.localStorage.getItem(key)
|
||||
return VueCookies.get(key)
|
||||
//return window.localStorage.getItem(key)
|
||||
}
|
||||
const saveToken = (key, token) => {
|
||||
//VueCookies.set(key, token, expireIn)
|
||||
window.localStorage.setItem(key, token)
|
||||
const saveToken = (key, token, expireIn) => {
|
||||
VueCookies.set(key, token, expireIn)
|
||||
//window.localStorage.setItem(key, token)
|
||||
}
|
||||
const destroyToken = (key) => {
|
||||
//VueCookies.remove(key)
|
||||
window.localStorage.removeItem(key)
|
||||
VueCookies.remove(key)
|
||||
//window.localStorage.removeItem(key)
|
||||
}
|
||||
const getAuthorizationHeader = (config) => {
|
||||
//로그인이 되었는지 확인후 Request시 헤더에 로그인정보 추가하기 위함
|
||||
|
||||
@ -30,15 +30,24 @@ const getters = {
|
||||
}
|
||||
}
|
||||
const mutations = {
|
||||
login: function (state, payload = {}) {
|
||||
state.takens = payload.tokens
|
||||
jwt.saveToken('access_token', payload.tokens.access_token)
|
||||
jwt.saveToken('refresh_token', payload.tokens.refresh_token)
|
||||
login: function (state, tokens = {}) {
|
||||
state.takens = tokens
|
||||
console.log(tokens)
|
||||
jwt.saveToken(
|
||||
'access_token',
|
||||
tokens.access_token.token,
|
||||
tokens.access_token.expiresIn
|
||||
)
|
||||
jwt.saveToken(
|
||||
'refresh_token',
|
||||
tokens.refresh_token.token,
|
||||
tokens.refresh_token.expiresIn
|
||||
)
|
||||
},
|
||||
logout: function (state) {
|
||||
state.takens = {}
|
||||
jwt.destroyTokens('access_token')
|
||||
jwt.destroyTokens('refresh_token')
|
||||
jwt.destroyToken('access_token')
|
||||
jwt.destroyToken('refresh_token')
|
||||
}
|
||||
}
|
||||
const actions = {
|
||||
@ -50,9 +59,9 @@ const actions = {
|
||||
return await apiServer
|
||||
.post('/auth/login', params)
|
||||
.then((response) => {
|
||||
console.log(response)
|
||||
const { data } = response
|
||||
//console.log(data)
|
||||
context.commit('login', { tokens: data })
|
||||
context.commit('login', data)
|
||||
return response
|
||||
})
|
||||
.catch((e) => {
|
||||
@ -72,7 +81,7 @@ const actions = {
|
||||
.post('/auth/register', params)
|
||||
.then((response) => {
|
||||
const { data } = response
|
||||
context.commit('login', { tokens: data.tokens })
|
||||
context.commit('login', data.tokens)
|
||||
return response
|
||||
})
|
||||
.catch((e) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user