Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown error, the response body from fetch is: undefined #1738

Closed
isamsamet opened this issue Sep 24, 2018 · 6 comments
Closed

Unknown error, the response body from fetch is: undefined #1738

isamsamet opened this issue Sep 24, 2018 · 6 comments
Labels
Cognito Related to cognito issues

Comments

@isamsamet
Copy link

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);
        }
    });`
@jordanranz jordanranz added the Cognito Related to cognito issues label Sep 24, 2018
@sanudatta11
Copy link

I am in the same issue

@mattbryce93
Copy link

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.

@sanudatta11
Copy link

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

@PrashantTapase
Copy link

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

working

@powerful23
Copy link
Contributor

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

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Cognito Related to cognito issues
Projects
None yet
Development

No branches or pull requests

6 participants