fix: unattended component reload due to session changes (#407)

* fix: unattended component reload due to session changes

When the session is updated, status goes back to loading then
authenticated or unauthenticated. session.accessTokenExpires may also be
updated.

This triggered various component refresh at unattented times, and brake
the user experience.

By splitting to only what's needed with memoization, it will prevent
unattented refresh.

* review

* review: change syntax
This commit is contained in:
2024-09-05 10:46:47 -06:00
committed by GitHub
parent c5f7fcc06b
commit db714f6390
9 changed files with 124 additions and 37 deletions

View File

@@ -16,7 +16,7 @@ import {
} from "@chakra-ui/react";
import { FaShare } from "react-icons/fa";
import useApi from "../../lib/useApi";
import { useSession } from "next-auth/react";
import useSessionUser from "../../lib/useSessionUser";
import { CustomSession } from "../../lib/types";
import { Select } from "chakra-react-select";
import ShareLink from "./shareLink";
@@ -70,9 +70,7 @@ export default function ShareAndPrivacy(props: ShareAndPrivacyProps) {
setShareLoading(false);
};
const { data: session } = useSession();
const customSession = session as CustomSession;
const userId = customSession?.user?.id;
const userId = useSessionUser().id;
useEffect(() => {
setIsOwner(!!(requireLogin && userId === props.transcriptResponse.user_id));