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 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
29 lines
670 B
TypeScript
29 lines
670 B
TypeScript
"use client";
|
|
import { signOut, signIn } from "next-auth/react";
|
|
import useSessionStatus from "../lib/useSessionStatus";
|
|
import { Spinner, Link } from "@chakra-ui/react";
|
|
|
|
export default function UserInfo() {
|
|
const { isLoading, isAuthenticated } = useSessionStatus();
|
|
|
|
return isLoading ? (
|
|
<Spinner size="xs" thickness="1px" className="mx-3" />
|
|
) : !isAuthenticated ? (
|
|
<Link
|
|
href="/"
|
|
className="font-light px-2"
|
|
onClick={() => signIn("authentik")}
|
|
>
|
|
Log in
|
|
</Link>
|
|
) : (
|
|
<Link
|
|
href="#"
|
|
className="font-light px-2"
|
|
onClick={() => signOut({ callbackUrl: "/" })}
|
|
>
|
|
Log out
|
|
</Link>
|
|
);
|
|
}
|