Skip to content

Instantly share code, notes, and snippets.

@luiseok
Last active July 7, 2018 12:44
Show Gist options
  • Save luiseok/6c8d161fd9c03507aac0c3bae931127d to your computer and use it in GitHub Desktop.
Save luiseok/6c8d161fd9c03507aac0c3bae931127d to your computer and use it in GitHub Desktop.
blog posting
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