diff --git a/beszel/site/src/components/navbar.tsx b/beszel/site/src/components/navbar.tsx index 034ae9d..89ae1c5 100644 --- a/beszel/site/src/components/navbar.tsx +++ b/beszel/site/src/components/navbar.tsx @@ -15,7 +15,7 @@ import { LangToggle } from "./lang-toggle" import { ModeToggle } from "./mode-toggle" import { Logo } from "./logo" import { pb } from "@/lib/stores" -import { cn, isReadOnlyUser, isAdmin } from "@/lib/utils" +import { cn, isReadOnlyUser, isAdmin, logOut } from "@/lib/utils" import { DropdownMenu, DropdownMenuTrigger, @@ -99,7 +99,7 @@ export default function Navbar() { )} - pb.authStore.clear()}> + Log Out diff --git a/beszel/site/src/lib/utils.ts b/beszel/site/src/lib/utils.ts index 1586b0e..8f8a5e6 100644 --- a/beszel/site/src/lib/utils.ts +++ b/beszel/site/src/lib/utils.ts @@ -33,7 +33,7 @@ const verifyAuth = () => { pb.collection("users") .authRefresh() .catch(() => { - pb.authStore.clear() + logOut() toast({ title: t`Failed to authenticate`, description: t`Please log in again`, @@ -65,6 +65,11 @@ export const updateSystemList = (() => { } })() +/** Logs the user out by clearing the auth store and unsubscribing from realtime updates. */ +export async function logOut() { + pb.authStore.clear() + pb.realtime.unsubscribe() +} export const updateAlerts = () => { pb.collection("alerts")