gpt4 book ai didi

reactjs - MISSING_CUSTOM_TOKEN

转载 作者:行者123 更新时间:2023-12-05 08:22:33 24 4
gpt4 key购买 nike

从后端获取 token ,当我在我的控制台中添加此错误显示的所有内容时:我的 React Authentication 不工作。 (firebase react )在我的控制台中,我的网络身份验证失败。它告诉我不能发布网址。这个错误:var error = new Error(message);

    Error: "Request failed with status code 400"

    createError createError.js:16

    settle settle.js:17

    handleLoad xhr.js:61

In Network Response this error is showing :

{

  "error": {

    "code": 400,

    "message": "MISSING_CUSTOM_TOKEN",

    "errors": [

      {

        "message": "MISSING_CUSTOM_TOKEN",

        "domain": "global",

        "reason": "invalid"

      }

    ]

  }

}

在我的项目中我有这样的:

   axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]', authData)

这是我的代码:


This is my code :

auth.js :

import axios from 'axios';

import * as actionTypes from './actionTypes';

export const authStart = () => {

return {

type: actionTypes.AUTH_START

};

};

export const authSuccess = (authData) => {

     return {

      type: actionTypes.AUTH_SUCCESS,

      authData: authData

     };

};

export const authFail = (error) => {

   return {

      type: actionTypes.AUTH_FAIL,

      error: error

   };

};

export const auth = (email, password) => {

return dispatch => {

dispatch(authStart());

    const authData = {

       email: email,

       password: password,

       returnSecureToken: true

    };

  axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=[API_KEY]', authData)

       .then(response => {

        console.log(response);

         dispatch(authSuccess(response.data));

      })

       .catch(err => {

          console.log(err);

          dispatch(authFail(err));

       });

};

};

最佳答案

您似乎将请求发送到错误的端点。您应该使用此端点进行用户注册:

https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]

还有这个用于登录:

https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=[API_KEY]

顺便说一下,不要忘记用您项目的 API key 替换“[API_KEY]”。

P.S.:你也可以仔细看看这个官方文档:

https://firebase.google.com/docs/reference/rest/auth

关于reactjs - MISSING_CUSTOM_TOKEN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61084292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com