Files
reflector/www/app/(auth)/userInfo.tsx
Mathieu Virbel db714f6390 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
2024-09-05 18:46:47 +02:00

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>
);
}