Fix refreshToken() undefined config, wrong axios.defaults, and missing re-throw

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 07:40:48 +08:00
parent 43283aab95
commit 2768b5d052
2 changed files with 52 additions and 5 deletions

View File

@@ -61,6 +61,11 @@ export default defineStore('loginStore', {
*/
async refreshToken() {
const api = '/api/oauth/token';
const config = {
headers: {
'Content-Type':'application/x-www-form-urlencoded',
},
};
this.auth.grant_type = 'refresh_token';
this.auth.refresh_token = getCookie("luciaRefreshToken");
@@ -70,15 +75,16 @@ export default defineStore('loginStore', {
if(response.status === 200) {
const newAccessToken = response.data.access_token;
const newRefreshToken = response.data.refresh_token;
document.cookie = `luciaToken=${newAccessToken}`;
document.cookie = `luciaRefreshToken=${newRefreshToken};expires=${this.expired}`;
defaults.headers.common['Authorization'] = `Bearer ${newAccessToken}`;
}
document.cookie = `luciaRefreshToken=${newRefreshToken};expires=${new Date(this.expired)}`;
axios.defaults.headers.common['Authorization'] = `Bearer ${newAccessToken}`;
}
} catch(error) {
// 若refresh token 失敗則導向至登入頁面
this.$router.push('/login');
throw error;
}
},
/**