Skip to content

Commit

Permalink
Merge pull request #34 from kewool/master
Browse files Browse the repository at this point in the history
login test
  • Loading branch information
kewool authored Mar 31, 2022
2 parents 8e1d39e + a1474da commit 7459244
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ export default {
},
beforeCreate(){
if(this.$cookies.get("Refresh") !== null){
getAccessToken()
setInterval(getAccessToken, 3600000)
}//else if(!window.location.href.includes("/login/token")){
this.checkLogin()
//else if(!window.location.href.includes("/login/token")){
// this.$router.replace("/login")
// }
},
methods:{
checkLogin(){
getAccessToken().then((status)=>{
if(status === 401) this.$router.replace("/login")
else setInterval(getAccessToken, 3600000)
})
}
},
computed:{
getAuthToken(){
Expand Down
5 changes: 3 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const getAPI = axios.create({
})

export async function getAccessToken() {
let accessToken = await getAPI.get("/auth/refresh").then((res) => res.data.accessToken).catch((e) => console.log(e))
let status
let accessToken = await getAPI.get("/auth/refresh").then((res) => res.data.accessToken).catch((e) => status = e.response.status)
store.commit("changeAccessToken", accessToken)
getAPI.defaults.headers.common['Authorization'] = accessToken
return accessToken
return status
}

export async function getUserData(){
Expand Down

0 comments on commit 7459244

Please sign in to comment.