【问题标题】:Firebase auth rest api using axiosFirebase auth rest api 使用 axios
【发布时间】:2020-08-29 13:35:51
【问题描述】:

我正在尝试在 Rect Native 项目上使用 Firebase REST API 和 Axios:

无论我做什么......我总是收到同样的错误:

handleLogin = () => {
        //alert('trying to login....');
        const onSuccess = ({ data }) => {
            alert('Success!!!!');
            // Set JSON Web Token on success
            //setClientToken(data.token);
            this.setState({ isLoading: false, isAuthorized: true });
            navigation.navigate('Home');
        };

        const onFailure = (error) => {
            alert('Error!!!!');
            console.log(error && error.response);
            this.setState({ errors: error.response.data, isLoading: false });
        };
        const signupUser = async () => {
            try {
                // set the url
                const url =
                    'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=.............';
                // request data object
                const data = {
                    email: this.state.email,
                    password: this.state.password,
                    returnSecureToken: true,
                };

                // set the headers
                const config = {
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                };

                const res = await axios.post(url, data, config);
                console.log(res.data);
                onSuccess(res.data);
            } catch (err) {
                console.error(err);
                onFailure(err);
            }
        };
        signupUser();
    };

我总是收到带有相同响应的错误 400:

“代码”:400, “错误”:数组 [ 目的 { “域”:“全球”, "消息": "ADMIN_ONLY_OPERATION", “原因”:“无效”,

有人知道我做错了什么吗,谢谢!

【问题讨论】:

    标签: javascript react-native firebase-authentication axios


    【解决方案1】:

    如果有人需要这个......

    这里有个问题:

    const config = {
                        headers: {
                            'Content-Type': 'application/json',
                        },
                    }; 
    

    【讨论】:

      猜你喜欢
      • 2020-12-25
      • 2020-02-16
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2021-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多