Last active
July 7, 2018 12:44
-
-
Save luiseok/6c8d161fd9c03507aac0c3bae931127d to your computer and use it in GitHub Desktop.
blog posting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const actions = { | |
async nuxtServerInit({commit}, {req}) { | |
let cookie = req.headers.cookie.split(';').find(c => c.trim().startsWith('token=')); | |
if (cookie == "" || | |
cookie == null || | |
cookie == undefined || | |
(cookie != null && typeof cookie == "object" && !Object.keys(cookie).length)) return | |
else { | |
//jwt 토큰이 있는 경우 | |
let apiToken = cookie.split('=')[1]; | |
const {status, data} = await rest.auth.fetchUserinfo(apiToken); | |
if(status === 200) | |
commit([Constants.SET_USER], data); | |
else | |
commit([Constants.SET_USER], null); | |
} | |
}, | |
async [Constants.LOGIN]({state, commit}, code) { | |
//code : String | |
const {data} = await rest.auth.loginWithGoogle(code); | |
commit([Constants.SET_USER], data); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment