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:
parent
26df1e921a
commit
0159bf18e0
2 changed files with 2 additions and 38 deletions
|
@ -3,10 +3,7 @@ import { setContext } from "@apollo/client/link/context";
|
||||||
import { createPersistedQueryLink } from "apollo-link-persisted-queries";
|
import { createPersistedQueryLink } from "apollo-link-persisted-queries";
|
||||||
|
|
||||||
import cachedZones from "./cached-data/zones.json";
|
import cachedZones from "./cached-data/zones.json";
|
||||||
import {
|
import { getAuthModeFeatureFlag } from "./components/useCurrentUser";
|
||||||
getAuthModeFeatureFlag,
|
|
||||||
readCypressLoginData,
|
|
||||||
} from "./components/useCurrentUser";
|
|
||||||
|
|
||||||
// Teach Apollo to load certain fields from the cache, to avoid extra network
|
// 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
|
// 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) {
|
async function getAccessToken(getAuth0) {
|
||||||
// Our Cypress tests store login data separately. Use it if available!
|
// Wait for auth0 to stop loading, so we can maybe get a token!
|
||||||
const cypressToken = readCypressLoginData()?.encodedToken;
|
|
||||||
if (cypressToken) {
|
|
||||||
return cypressToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, 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.
|
// We'll do this hackily by checking every 100ms until it's true.
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
function check() {
|
function check() {
|
||||||
|
|
|
@ -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") {
|
if (authMode === "auth0") {
|
||||||
return currentUserViaAuth0;
|
return currentUserViaAuth0;
|
||||||
} else if (authMode === "db") {
|
} 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) {
|
function getUserInfoFromAuth0Data(user) {
|
||||||
return {
|
return {
|
||||||
id: user.sub?.match(/^auth0\|impress-([0-9]+)$/)?.[1],
|
id: user.sub?.match(/^auth0\|impress-([0-9]+)$/)?.[1],
|
||||||
|
|
Loading…
Reference in a new issue