bombom
bombom

Reputation: 117

MISSING_CUSTOM_TOKEN

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

       });

    };

   };

Upvotes: 2

Views: 7033

Answers (4)

Barry P
Barry P

Reputation: 91

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.

Upvotes: 0

Akshay Sharma
Akshay Sharma

Reputation: 69

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

Upvotes: 0

morteza.bahrami
morteza.bahrami

Reputation: 121

It seems you are sending your request to the wrong Endpoint. You should use this endpoint for user sign-up:

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

And This one for sign-in:

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

By the way, don't forget to replace "[API_KEY]" with your project's API key.

P.S.: You can also take a closer look at this official doc:

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

Upvotes: 12

codeKid
codeKid

Reputation: 75

Your URL is incorrect in your post request.

At the end of the URL you have to replace the "[API_KEY]" with your identical API key.

You can find it in Firebase by clicking on "Project Settings" and copy the value from "Web API Key" field.

example: Web API Key: AbCdEf

Your URL should be: 'https://identitytoolkit.googleapis.com/v1/accounts:signInWithCustomToken?key=AbCdEf'

Upvotes: 3

Related Questions