首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Firebase调度错误对象{“错误”:“auth标题中的无效索赔‘claim’:'tB0M2A‘与iat:’1659290899‘,}

Firebase调度错误对象{“错误”:“auth标题中的无效索赔‘claim’:'tB0M2A‘与iat:’1659290899‘,}
EN

Stack Overflow用户
提问于 2022-07-31 18:12:03
回答 1查看 46关注 0票数 0

我正在努力开发一个反应本地应用程序,但一切都很好。一旦更改了防火墙实时数据库中的身份验证规则。从那时起,我无法从消防基地张贴/收到任何请求。我正在存储在redux中应用程序中的用户签名之后返回的idToken。

代码语言:javascript
运行
复制
case actionTypes.AUTHENTICATE_USER:
        return {
            ...state,
            isAuth: true,
            token: action.payload
        }

export const authUser = token => {
return {
    type: actionTypes.AUTHENTICATE_USER,
    payload: token
}}

登录操作代码如下:

代码语言:javascript
运行
复制
export const tryLogin = (email, password, navigate) => dispatch => {
fetch("https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + API_KEY, {
    method: "POST",
    body: JSON.stringify({
        email: email, password: password, returnSecuretoken: true
    }),
    headers: {
        "Content-Type": "application/json"
    }
})
    .catch(err => {
        console.log(err);
        alert("Authentication Failed");
    })
    .then(res => res.json())
    .then(data => {
        if (data.error) {
            alert(data.error.message);
        }
        else {
            dispatch(authUser(data.idToken));
            navigate("Home");
        }
        console.log(data);
    })}

在运行以下代码时,我得到了错误:

代码语言:javascript
运行
复制
export const addPlace = place => (dispatch, getState) => {
let token = getState().token;
console.log("Add place Token:", token);
fetch(`https://first-react-native-proje-7df03-default-rtdb.asia-southeast1.firebasedatabase.app/places.json?auth=${token}`, {
    method: "POST", body: JSON.stringify(place)
})
    .catch(error => console.log(error))
    .then(response => response.json())
    .then(data => console.log("Dispatch Error", data))}


export const loadPlaces = () => (dispatch, getState) => {
let token = getState().token;
fetch(`https://first-react-native-proje-7df03-default-rtdb.asia-southeast1.firebasedatabase.app/places.json?auth=${token}`)
    .catch(err => {
        alert("Something Went Wrong, Sorry!");
        console.log(err);
    })
    .then(res => res.json())
    .then(data => {
        const places = [];
        for (let key in data) {
            places.push({
                ...data[key],
                key: key
            })
        }
        dispatch(setPlaces(places));
    })}

我的基本规则如下,因为我仍处于初级阶段:

代码语言:javascript
运行
复制
{"rules": {
  ".read": "auth!=null" ,  // 2022-8-4
".write": "auth!=null",  // 2022-8-4
}}

我没有办法解决这个问题。请帮帮忙。

EN

回答 1

Stack Overflow用户

发布于 2022-07-31 18:42:51

解决了。问题是返回安全托肯:是的。我编写了returnSecuretoken,它创建了错误。它将是:

代码语言:javascript
运行
复制
export const tryLogin = (email, password, navigate) => dispatch => {
fetch("https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=" + API_KEY, {
    method: "POST",
    body: JSON.stringify({
        email: email, password: password, ***returnSecureToken: true***
    }),
    headers: {
        "Content-Type": "application/json"
    }
})
    .catch(err => {
        console.log(err);
        alert("Authentication Failed");
    })
    .then(res => res.json())
    .then(data => {
        if (data.error) {
            alert(data.error.message);
        }
        else {
            dispatch(authUser(data.idToken));
            navigate("Home");
        }
        console.log(data);
    })

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73185814

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档