mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 12:19:06 +00:00
* 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
23 lines
561 B
TypeScript
23 lines
561 B
TypeScript
"use client";
|
|
|
|
import { useState, useEffect } from "react";
|
|
import { useSession as useNextAuthSession } from "next-auth/react";
|
|
import { Session } from "next-auth";
|
|
|
|
export default function useSessionStatus() {
|
|
const { status: naStatus } = useNextAuthSession();
|
|
const [status, setStatus] = useState("loading");
|
|
|
|
useEffect(() => {
|
|
if (naStatus !== "loading" && naStatus !== status) {
|
|
setStatus(naStatus);
|
|
}
|
|
}, [naStatus]);
|
|
|
|
return {
|
|
status,
|
|
isLoading: status === "loading",
|
|
isAuthenticated: status === "authenticated",
|
|
};
|
|
}
|