---
# System prepended metadata

title: PLAYER Refresh Token

---

# PLAYER Refresh Token

> App.vue[color=blue]

:baby_chick: 新增屬性 **created()** 
:baby_chick: 讓每次進入網頁的時候都先 Refresh Token
:baby_chick: 使用vuex的dispatch去找actions來用
```javascript=
export default {
  components:{
    myHeader,
    myFooter
  },
  //在每次載入之前，先重置token
  created(){
    this.$store.dispatch('admin/refreshToken');
  }
}
```
## 
## 如何Refresh token

Firebase auth API 指南
https://firebase.google.com/docs/reference/rest/auth#section-refresh-token

> 進入 admin.js - **actions**[color=coral]

:baby_chick: 新增 **refreshToken** 
```javascript=
refreshToken({commit}){
            const refreshToken = localStorage.getItem("refresh");

            if(refreshToken){
                Vue.http.post(`https://securetoken.googleapis.com/v1/
                token?key=${FbApiKey}`,{
                    grant_type: 'refresh_token',
                    refresh_token: refreshToken
                })
                .then( res => res.json())
                .then( authData => {
                    commit("authUser",{
                        idToken: authData.id_token,
                        refreshToken: authData.refresh_token,
                        type:'refresh'
                    });
                    localStorage.setItem("token",authData.id_token)
                    localStorage.setItem("refresh",authData.refresh_token)
                }) 
            } else {
                console.log('cannot fresh token')
            }
        }
```
> 進入 admin.js - **mutiations**[color=coral]
> 
:baby_chick: 取得