我已經在我的網站上實現了 firebase 登錄,我將信息發送到我的服務器。我在那里創建會話和 csrf 令牌。但我發現如果我的 csrf 不匹配,我會收到錯誤,但該函數會繼續運行,就像登錄成功一樣。這是代碼:postIdTokenToSessionLogin("/sessionLogin", idToken, csrfToken).then( function() { // Redirect to profile on success. console.log("login succesful"); //this gets logged even if "postIdTokenToSessionLogin" gets caught // window.location.assign("/profile"); }, function(error) { console.log(error); //i need this to run window.location.assign("/"); } );postIdTokenToSessionLogin = async function(url, idToken, csrfToken) { // POST to session login endpoint. const data = { idToken, _csrf: csrfToken }; console.log(data); options = { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" } }; // POST to session login endpoint. return fetch(url, options).catch(err => { throw err; //---------here i do get the error, });};我哪里錯了?
1 回答

PIPIONE
TA貢獻1829條經驗 獲得超9個贊
您必須依賴ok以下屬性Response:
fetch('https://httpbin.org/status/500')
.then(res => {
if (res.ok) {
return res;
} else {
throw res;
}
}).catch(err => {
console.error('Error: ', err.status);
});
- 1 回答
- 0 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消