Skip to content

Instantly share code, notes, and snippets.

View sir-dunxalot's full-sized avatar
💭
I may be slow to respond.

Duncan Walker sir-dunxalot

💭
I may be slow to respond.
  • Boston, MA
View GitHub Profile
@sir-dunxalot
sir-dunxalot / commands.js
Created May 26, 2020 03:11
cypress-nextjs-auth0__helper--login-with-multiple-users
Cypress.Commands.add('login', (credentials?: Credentials = {}) => {
const { username, password } = credentials;
const credentials = {
username: username || Cypress.env('auth0Username'),
password: password || Cypress.env('auth0Password'),
};
/* ... */
});
@sir-dunxalot
sir-dunxalot / commands.js
Last active May 26, 2020 20:48
cypress-nextjs-auth0__helper--login-with-cache
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');
@sir-dunxalot
sir-dunxalot / login.spec.js
Last active May 26, 2020 02:51
cypress-nextjs-auth0__spec--with-before
context('Logging in', () => {
before(() => {
cy.login();
});
it('should successfully log in', () => {
cy.visit('/');
cy.request('/api/me').then(({ body: user }) => {
@sir-dunxalot
sir-dunxalot / commands.js
Last active November 20, 2020 19:49
cypress-nextjs-auth0__helper--login-with-session
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');
@sir-dunxalot
sir-dunxalot / api-route.js
Created May 26, 2020 02:23
cypress-nextjs-auth0__route
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);
@sir-dunxalot
sir-dunxalot / cypress.env.json
Created May 26, 2020 02:02
cypress-nextjs-auth0__cypress-env
{
"auth0Domain": "YOURAPP.auth0.com",
"auth0Audience": "https://YOURAPP.auth0.com/api/v2/",
"auth0Username": "mytestuser@email.com",
"auth0Password": "mytestuserpassword",
"auth0Scope": "openid profile email",
"auth0ClientId": "YOURCLIENTID",
"auth0ClientSecret": "YOURCLIENTSECRET",
"auth0CookieSecret": "YOURCOOKIEID",
"sessionCookieName": "a0:session",
@sir-dunxalot
sir-dunxalot / commands.js
Created May 26, 2020 01:58
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;
@sir-dunxalot
sir-dunxalot / login.spec.js
Created May 26, 2020 01:34
cypress-nextjs-auth0__spec
context('Logging in', () => {
it('should successfully log in', () => {
cy.login().then(() => {
cy.visit('/');
cy.request('/api/me').then(({ body: user }) => {
expect(user).to.exist;
});
});
});
@sir-dunxalot
sir-dunxalot / README.md
Last active August 22, 2022 12:17
An example of Cypress, Auth0, and Next.js authentication for a local Cypress test

Edit:

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

This gist

@sir-dunxalot
sir-dunxalot / Ember.js and Disqus Component
Last active December 30, 2017 19:07
An Ember.js Disqus component that loads Disqus comments asyncronously
'use strict';
/**
Add your info here to link this blog to your free Disqus account
*/
App.DisqusOptions = Em.Object.create({
shortname: 'someNamehere', // Change this!
});