MISSING_CUSTOM_TOKEN

Viewed 4897

Getting a token from the backend ,when i add every thing this error is showing in my console : My React Authentication is not working. (firebase react) In my console my network authentication is failing. Its telling me cannot post url. This error : 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"

      }

    ]

  }

 }

In my project I had at this :

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

This is my code :


   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));

       });

    };

   };

4 Answers

Yeh! I got stuck in the same problem...here's the solution

  1. Your post URL is wrong it's for the singInToken instead use this link

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

  2. You secondly your API key has been missing place your web API key use the below link

    https://console.firebase.google.com/project/_/settings/general/

    or go to the project settings and copy the web API key

Example:'https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=AbsdfydfF'

Hope! This works

I have this exact same problem listed above, but I AM using the correct endpoint URL and API Key. It's telling me the key is not found on the server, despite my Google Firebase Console Projects setting showing me that is the key. And, I have been using this key in development for some time now. Just today I started getting this behavior. Not sure what might have caused this.

Ok, I found a slight error on my end, unrelated to the API EP KEY. I had the following in an error return:

error: error.message

And it should have been

error: error

Problem solved.

Related