Allow use of useCurrentUser/useCurrentTeam hooks in unauthenticated components

This commit is contained in:
Tom Moor
2023-10-28 11:31:42 -04:00
parent 56f9755cd9
commit 964d2b6bb3
17 changed files with 109 additions and 71 deletions

View File

@@ -18,6 +18,7 @@ import { TeamContext } from "~/components/TeamContext";
import Text from "~/components/Text";
import env from "~/env";
import useBuildTheme from "~/hooks/useBuildTheme";
import useCurrentUser from "~/hooks/useCurrentUser";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import { AuthorizationError, OfflineError } from "~/utils/errors";
@@ -83,8 +84,9 @@ function useDocumentId(documentSlug: string, response?: Response) {
}
function SharedDocumentScene(props: Props) {
const { ui, auth } = useStores();
const { ui } = useStores();
const location = useLocation();
const user = useCurrentUser({ rejectOnEmpty: false });
const searchParams = React.useMemo(
() => new URLSearchParams(location.search),
[location.search]
@@ -104,10 +106,10 @@ function SharedDocumentScene(props: Props) {
const theme = useBuildTheme(response?.team?.customTheme, themeOverride);
React.useEffect(() => {
if (!auth.user) {
if (!user) {
void changeLanguage(detectLanguage(), i18n);
}
}, [auth, i18n]);
}, [user, i18n]);
// ensure the wider page color always matches the theme
React.useEffect(() => {