question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How should I use AWS Amplify instead of cy.request on the beforeEach in order to authenticate users?

See original GitHub issue

Hi!

How should I use aws amplify on the beforeEach in order to authenticate users? I am asking this because I am going to need the token to make other AWS requests later.

import Amplify, { Auth } from 'aws-amplify';
import aws_exports from './aws-exports.js';
Amplify.configure(aws_exports);

describe('TEST', function () {
  context('Querying', function () {
    beforeEach(function () {
      //
    })


    it('It should...', function () {
      Auth.signIn('test@test.com', 'EasyToGuess$333')
        .then(user => {
          console.log('===> user', user);

          let session = Auth.currentSession();

          console.log('===> session', session);
        })
        .catch(err => console.log('===> err', err));
    })
  })
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
christopherfrancecommented, Sep 19, 2019

You can confirm a user from the AWS CLI:

cy.exec(`aws cognito-idp admin-confirm-sign-up \
  --region us-east-1 \
  --user-pool-id ${config.cognito.USER_POOL_ID} \
  --username ${userEmail}`)
    console.log(`Confirmed ${userEmail}`)

Not sure about handling 2fa.

1reaction
brian-manncommented, Jun 18, 2018

You need to return Auth.signIn because it’s a promise and the test must be returned a promise to know to await the results of it.

Is aws-amplify a node only lib? Are you having issues with this? You’ve posted this issue but haven’t specified what the actual problem is… ?

If aws-amplify is a node only lib you can simply use cy.task to talk to the background node process and implement it there… something like cy.task('login', user, pass) and then do the same stuff you need to do in node and that’s it. Tasks are already promise aware so you just need to return the promise and be done with it.

If the promise rejects the command will automatically fail, etc. Same for succeeding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use Cypress to test AWS Amplify Apps with Authentication
We use the amplify Auth class to create a session for our user. · The Auth. · Extract the idToken and accessToken from...
Read more >
AWS Amplify allows you to mix and match authorization ...
Go to your Amplify app and enable click “Enable Admin UI”. This will provide you a visual interface to configure your backend. Once...
Read more >
AWS Amplify + Cognito Login and Component Testing with ...
Here we will use Auth from AWS-amplify to login using our environment variables and ... which then be used to validate the authentication...
Read more >
Amazon Cognito Authentication - Cypress Documentation
First, run the amplify init command to initialize the Cypress Real World App. This will provision the project with your AWS credentials. amplify...
Read more >
Is it okay to make API requests to set up tests in Cypress when ...
I do my E2E tests using Cypress. Before each test, I log the user in via the AWS Amplify CLI. Afterwards, I clear...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found