Skip to content

Instantly share code, notes, and snippets.

@sir-dunxalot
Created May 26, 2020 01:58
Show Gist options
  • Save sir-dunxalot/e4596ce78c7d77031dad34ec2e2218b8 to your computer and use it in GitHub Desktop.
Save sir-dunxalot/e4596ce78c7d77031dad34ec2e2218b8 to your computer and use it in GitHub Desktop.
cypress-nextjs-auth0__helper--login
import auth0 from 'auth0-js';
const auth = new auth0.WebAuth({
domain: Cypress.env('auth0Domain'),
clientID: Cypress.env('auth0ClientId'),
});
Cypress.Commands.add('login', (credentials) => {
const { username, password } = credentials;
return new Cypress.Promise((resolve, reject) => {
auth.client.loginWithDefaultDirectory({
username,
password,
audience: Cypress.env('auth0Audience'),
scope: Cypress.env('auth0Scope'),
client_secret: Cypress.env('auth0ClientSecret'),
}, (err, response) => {
if (err) {
reject(err);
} else {
resolve(response);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment