Created
November 6, 2020 20:48
-
-
Save Nxtra/891132ec175c36ba6af3a7a45869bb5d to your computer and use it in GitHub Desktop.
Cypress custom Amplify command.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cypress.Commands.add("signIn", () => { | |
cy.then(() => Auth.signIn(username, password)).then((cognitoUser) => { | |
const idToken = cognitoUser.signInUserSession.idToken.jwtToken; | |
const accessToken = cognitoUser.signInUserSession.accessToken.jwtToken; | |
const makeKey = (name) => `CognitoIdentityServiceProvider.${cognitoUser.pool.clientId}.${cognitoUser.username}.${name}`; | |
cy.setLocalStorage(makeKey("accessToken"), accessToken); | |
cy.setLocalStorage(makeKey("idToken"), idToken); | |
cy.setLocalStorage( | |
`CognitoIdentityServiceProvider.${cognitoUser.pool.clientId}.LastAuthUser`, | |
cognitoUser.username | |
); | |
}); | |
cy.saveLocalStorage(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment