mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
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:
@@ -10,7 +10,7 @@ import { useRouter } from "next/navigation";
|
||||
import useCreateTranscript from "../createTranscript";
|
||||
import SelectSearch from "react-select-search";
|
||||
import { supportedLanguages } from "../../../supportedLanguages";
|
||||
import { useSession } from "next-auth/react";
|
||||
import useSessionStatus from "../../../lib/useSessionStatus";
|
||||
import { featureEnabled } from "../../../domainContext";
|
||||
import { signIn } from "next-auth/react";
|
||||
import {
|
||||
@@ -44,9 +44,7 @@ import {
|
||||
} from "@chakra-ui/react";
|
||||
const TranscriptCreate = () => {
|
||||
const router = useRouter();
|
||||
const { status } = useSession();
|
||||
const sessionReady = status !== "loading";
|
||||
const isAuthenticated = status === "authenticated";
|
||||
const { isLoading, isAuthenticated } = useSessionStatus();
|
||||
const requireLogin = featureEnabled("requireLogin");
|
||||
|
||||
const [name, setName] = useState<string>("");
|
||||
@@ -141,7 +139,7 @@ const TranscriptCreate = () => {
|
||||
</Flex>
|
||||
<Flex flexDir="column" h="full" flexBasis="1" flexGrow={1}>
|
||||
<Center>
|
||||
{!sessionReady ? (
|
||||
{isLoading ? (
|
||||
<Spinner />
|
||||
) : requireLogin && !isAuthenticated ? (
|
||||
<Button onClick={() => signIn("authentik")} colorScheme="blue">
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user