Amplify-js: Unknown error, the response body from fetch is: undefined

Created on 24 Sep 2018  路  5Comments  路  Source: aws-amplify/amplify-js

I am using in Node.js the following versions
"amazon-cognito-identity-js": "^2.0.29",
"node-fetch": "^2.2.0",

I am trying to signUp and authenticateUser in my app.

Initially I was getting "fetch undefined" when I call singUp. Which was fixed by adding the node-fetch library. Now I can successfully signUp users.

Now I am getting the error "Unknown error, the response body from fetch is: undefined" when I call authenticateUser method. The code is as following.

`app.post('/login', (req, res) => {
var authenticationData = {
Username: req.body.email,
Password: req.body.password,
};

    var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);

    var userData = {
        Username: req.body.email,
        Pool: userPool
    };

    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            var accessToken = result.getAccessToken().getJwtToken();

            /* Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer*/
            var idToken = result.idToken.jwtToken;
        },
        onFailure: function (err) {
            console.log(err);
        }
    });`
Cognito

Most helpful comment

I removed the remember device and set it to no. It worked.

All 5 comments

I am in the same issue

I am using in Node.js the following versions
"amazon-cognito-identity-js": "^2.0.29",
"node-fetch": "^2.2.0",

I am trying to signUp and authenticateUser in my app.

Initially I was getting "fetch undefined" when I call singUp. Which was fixed by adding the node-fetch library. Now I can successfully signUp users.

Now I am getting the error "Unknown error, the response body from fetch is: undefined" when I call authenticateUser method. The code is as following.

`app.post('/login', (req, res) => {
var authenticationData = {
Username: req.body.email,
Password: req.body.password,
};

    var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);

    var userData = {
        Username: req.body.email,
        Pool: userPool
    };

    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            var accessToken = result.getAccessToken().getJwtToken();

            /* Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer*/
            var idToken = result.idToken.jwtToken;
        },
        onFailure: function (err) {
            console.log(err);
        }
    });`

@isamsamet Try adding this within the authenticate user function and use the log to to see what is needing defined:

      mfaSetup: function(challengeName, challengeParameters) {
        console.log('mfaSetup');
      },
      // @ts-ignore
      associateSecretCode : function(secretCode) {
        console.log('associateSecretCode');
      },

      selectMFAType : function(challengeName, challengeParameters) {
        console.log('selectMFAType');
      },

      totpRequired : function(secretCode) {
        console.log('totpRequired');
      },

      mfaRequired: function (codeDeliveryDetails) {
        console.log('mfaRequired');
      }

Some of these will be required depending on the User Pool configuration. Have a look at use case 23 and 27 for how these blocks should be configured. Use cases here.

I removed the remember device and set it to no. It worked.

I removed the remember device and set it to no. It worked.

working

Closing the issue as you will no longer receive unknown error in the latest version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leantide picture leantide  路  3Comments

cosmosof picture cosmosof  路  3Comments

cgarvis picture cgarvis  路  3Comments

guanzo picture guanzo  路  3Comments

callmekatootie picture callmekatootie  路  3Comments