Remove Cypress login hacks

We previously had a lil trick to help Cypress perform an Auth0 login without using the whole Auth0 UI. (I forget exactly why!)

With Cypress deleted, we don't need this code anymore!
This commit is contained in:
Emi Matchu 2022-09-14 17:45:53 -07:00
parent 26df1e921a
commit 0159bf18e0
2 changed files with 2 additions and 38 deletions

View file

@ -3,10 +3,7 @@ import { setContext } from "@apollo/client/link/context";
import { createPersistedQueryLink } from "apollo-link-persisted-queries";
import cachedZones from "./cached-data/zones.json";
import {
getAuthModeFeatureFlag,
readCypressLoginData,
} from "./components/useCurrentUser";
import { getAuthModeFeatureFlag } from "./components/useCurrentUser";
// Teach Apollo to load certain fields from the cache, to avoid extra network
// requests. This happens a lot - e.g. reusing data from item search on the
@ -192,13 +189,7 @@ const authModeLink = setContext((_, { headers = {} }) => {
});
async function getAccessToken(getAuth0) {
// Our Cypress tests store login data separately. Use it if available!
const cypressToken = readCypressLoginData()?.encodedToken;
if (cypressToken) {
return cypressToken;
}
// Otherwise, wait for auth0 to stop loading, so we can maybe get a token!
// Wait for auth0 to stop loading, so we can maybe get a token!
// We'll do this hackily by checking every 100ms until it's true.
await new Promise((resolve) => {
function check() {

View file

@ -40,17 +40,6 @@ function useCurrentUser() {
};
}
// Additionally, our Cypress tests do an actual end-to-end login as a test
// user. Use that token if present!
const cypressUser = readCypressLoginData()?.decodedUser;
if (cypressUser) {
return {
isLoading: false,
isLoggedIn: true,
...getUserInfoFromAuth0Data(cypressUser),
};
}
if (authMode === "auth0") {
return currentUserViaAuth0;
} else if (authMode === "db") {
@ -133,22 +122,6 @@ function useCurrentUserViaDb({ isEnabled }) {
}
}
export function readCypressLoginData() {
const cypressUserJsonString = window.localStorage.getItem("auth0Cypress");
if (!cypressUserJsonString) {
return null;
}
try {
return JSON.parse(cypressUserJsonString);
} catch (e) {
console.warn(
"Could not parse auth0Cypress token in localStorage; ignoring."
);
return null;
}
}
function getUserInfoFromAuth0Data(user) {
return {
id: user.sub?.match(/^auth0\|impress-([0-9]+)$/)?.[1],