Axios headers authorization bearer is missing on callback
我目前正在客户端应用程序上使用
我在另一个
我尝试在回调的标头
这不起作用:在回调(
当
如果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | let now = new Date(); let time = now.getTime(); time += 3600 * 1000; now.setTime(time); const setTokenOnCookie = (token) => { document.cookie = 'token=' + token + '; expires=' + now.toUTCString(); } const setRefreshOnCookie = (refresh_token) => { document.cookie = 'refresh_token=' + refresh_token; } const TOKEN_USER = document.cookie.replace(/(?:(?:^|.*;\\s*)token\\s*\\=\\s*([^;]*).*$)|^.*$/,"$1"); const REFRESH_TOKEN = document.cookie.replace(/(?:(?:^|.*;\\s*)refresh_token\\s*\\=\\s*([^;]*).*$)|^.*$/,"$1"); const refreshToken = (userAuthCallback, userUnauthCallback) => { axios.post(`${API_URL}/my/url/to/refresh/token`, 'refresh_token='+REFRESH_TOKEN, {headers:{'Content-Type': 'application/x-www-form-urlencoded'}} ).then(res => { Promise.all([setTokenOnCookie(res.data.token), setRefreshOnCookie(res.data.refresh_token)]) .then(()=>{ userAuthCallback(res.data.token); }).catch(err => { userUnauthCallback(); }) } const userAuth = (token) => { if(!token){ token = TOKEN_USER } axios.get(`${API_URL}/my/url/to/get/my/user`, {headers:{'Authorization': `Bearer ${token}`}} ).then(res => { pushToApplicationPath(); }).catch(err => { catchMyError(); }) } const userUnauth = () => { document.cookie = 'token=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; document.cookie = 'refresh_token=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; document.cookie = 'username=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; pushToLoginPath(); } refreshToken(userAuth, userUnauth); |
您知道问题出在哪里吗?
我在GitHub上发现了未解决的问题。
GitHub问题891