스터디 내용
- Post로 로그인 토큰을 요청
- 로그인 토큰이 성공하면 유저정보를 요청하여서 로그인한다.
스터디 후기
- 어제와 별다를것 없는 내용이였다.
- axios의 Post
.post("https://reqres.in/api/login", loginObj)
.get("https://reqres.in/api/users/2", config)
login({ commit }, loginObj) {
axios
.post("https://reqres.in/api/login", loginObj)
.then(res => {
let token = res.data.token
let config = {
headers: {
"access-token": token
}
}
axios
.get("https://reqres.in/api/users/2", config)
.then(response => {
let userInfo = {
id: response.data.data.id,
first_name: response.data.data.first_name,
last_name: response.data.data.last_name,
avatar: response.data.data.avatar
}
commit("loginSuccess", userInfo)
})
.catch(error => {
alert("이메일과 비밀번호를 확인하세요.")
console.log(error)
})
})
.catch(err => {
console.log(err)
})
}