How should I use AWS Amplify instead of cy.request on the beforeEach in order to authenticate users?
See original GitHub issueHi!
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:
- Created 5 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can confirm a user from the AWS CLI:
Not sure about handling 2fa.
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 anode
only lib you can simply usecy.task
to talk to the background node process and implement it there… something likecy.task('login', user, pass)
and then do the same stuff you need to do innode
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.