Since writing this gist, sir-dunxalot/cypress-nextjs-auth0 was released, which encapsulates this gist in a more user-friendly way. Try it out:
yarn add cypress-nextjs-auth0 --dev| Cypress.Commands.add('login', (credentials?: Credentials = {}) => { | |
| const { username, password } = credentials; | |
| const credentials = { | |
| username: username || Cypress.env('auth0Username'), | |
| password: password || Cypress.env('auth0Password'), | |
| }; | |
| /* ... */ | |
| }); |
| import auth0 from 'auth0-js'; | |
| import Iron from '@hapi/iron'; | |
| const auth = new auth0.WebAuth({ | |
| domain: Cypress.env('auth0Domain'), | |
| clientID: Cypress.env('auth0ClientId'), | |
| }); | |
| const sessionCookieName = Cypress.env('sessionCookieName'); | |
| const stateCookieName = Cypress.env('stateCookieName'); |
| context('Logging in', () => { | |
| before(() => { | |
| cy.login(); | |
| }); | |
| it('should successfully log in', () => { | |
| cy.visit('/'); | |
| cy.request('/api/me').then(({ body: user }) => { |
| import auth0 from 'auth0-js'; | |
| import Iron from '@hapi/iron'; | |
| const auth = new auth0.WebAuth({ | |
| domain: Cypress.env('auth0Domain'), | |
| clientID: Cypress.env('auth0ClientId'), | |
| }); | |
| const sessionCookieName = Cypress.env('sessionCookieName'); | |
| const stateCookieName = Cypress.env('stateCookieName'); |
| import { initAuth0 } from '@auth0/nextjs-auth0'; | |
| const auth0Config = { /*...*/ }; | |
| const auth0 = initAuth0(auth0Config); | |
| const route = async function me(req, res) { | |
| try { | |
| await auth0.handleProfile(req, res, {}); | |
| } catch (error) { | |
| console.error(error); |
| { | |
| "auth0Domain": "YOURAPP.auth0.com", | |
| "auth0Audience": "https://YOURAPP.auth0.com/api/v2/", | |
| "auth0Username": "[email protected]", | |
| "auth0Password": "mytestuserpassword", | |
| "auth0Scope": "openid profile email", | |
| "auth0ClientId": "YOURCLIENTID", | |
| "auth0ClientSecret": "YOURCLIENTSECRET", | |
| "auth0CookieSecret": "YOURCOOKIEID", | |
| "sessionCookieName": "a0:session", |
| 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; |
| context('Logging in', () => { | |
| it('should successfully log in', () => { | |
| cy.login().then(() => { | |
| cy.visit('/'); | |
| cy.request('/api/me').then(({ body: user }) => { | |
| expect(user).to.exist; | |
| }); | |
| }); | |
| }); |
Since writing this gist, sir-dunxalot/cypress-nextjs-auth0 was released, which encapsulates this gist in a more user-friendly way. Try it out:
yarn add cypress-nextjs-auth0 --dev| 'use strict'; | |
| /** | |
| Add your info here to link this blog to your free Disqus account | |
| */ | |
| App.DisqusOptions = Em.Object.create({ | |
| shortname: 'someNamehere', // Change this! | |
| }); |