Oops, fix mistakes turning on experimental log

I didn't notice that there was another place where "auth0" was set as the default, oops!

This caused logins to fail, because the cookie would be set, but the request wouldn't be sent with the correct `DTIAuthMode` header. So you'd stay logged in with your auth0 credentials, even though the UI was using your db cookies. Or something? Idk weird state mismatch.

Point being, fixed now!
This commit is contained in:
Emi Matchu 2022-09-14 18:12:34 -07:00
parent 26d7f4220a
commit 2c54e356f9

View file

@ -1,6 +1,5 @@
import { gql, useMutation, useQuery } from "@apollo/client";
import { useAuth0 } from "@auth0/auth0-react";
import { useEffect } from "react";
import { useLocalStorage } from "../util";
const NOT_LOGGED_IN_USER = {
@ -184,11 +183,11 @@ export function useLogout() {
}
/**
* useAuthModeFeatureFlag returns "auth0" by default, but "db" if you're trying
* the new db-backed login mode.
* useAuthModeFeatureFlag returns "db" by default, but "auto" if you're falling
* back to the old auth0-backed login mode.
*
* To set this manually, run `window.setAuthModeFeatureFlag("db")` in your
* browser console.
* To set this manually, click "Better login system" on the homepage in the
* Coming Soon block, and switch the toggle.
*/
export function useAuthModeFeatureFlag() {
// We'll probably add a like, experimental gradual rollout thing here too.
@ -201,10 +200,6 @@ export function useAuthModeFeatureFlag() {
null
);
useEffect(() => {
window.setAuthModeFeatureFlag = setAuthModeFeatureFlag;
});
if (!["auth0", "db", null].includes(savedValue)) {
console.warn(
`Unexpected DTIAuthModeFeatureFlag value: %o. Ignoring.`,
@ -242,23 +237,7 @@ export function getAuthModeFeatureFlag() {
savedValue = null;
}
return savedValue || "auth0";
}
/**
* setAuthModeFeatureFlag is mounted on the window, so you can call it from the
* browser console to set this override manually.
*/
function setAuthModeFeatureFlag(newValue) {
if (!["auth0", "db", null].includes(newValue)) {
throw new Error(`Auth mode must be "auth0", "db", or null.`);
}
localStorage.setItem("DTIAuthModeFeatureFlag", JSON.stringify(newValue));
// The useLocalStorage hook isn't *quite* good enough to catch this change.
// Let's just reload the page lmao.
window.location.reload();
return savedValue || "db";
}
export default useCurrentUser;