auth: ensure realtime subscriptions are cleared on logout

This commit is contained in:
Henry Dollman
2025-02-05 20:24:39 -05:00
parent 2216e40f04
commit 1daf35406a
2 changed files with 8 additions and 3 deletions

View File

@@ -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() {
</>
)}
</DropdownMenuGroup>
<DropdownMenuItem onSelect={() => pb.authStore.clear()}>
<DropdownMenuItem onSelect={logOut}>
<LogOutIcon className="me-2.5 h-4 w-4" />
<span>
<Trans>Log Out</Trans>

View File

@@ -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")