mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 09:49:28 +08:00
auth: ensure realtime subscriptions are cleared on logout
This commit is contained in:
@@ -15,7 +15,7 @@ import { LangToggle } from "./lang-toggle"
|
|||||||
import { ModeToggle } from "./mode-toggle"
|
import { ModeToggle } from "./mode-toggle"
|
||||||
import { Logo } from "./logo"
|
import { Logo } from "./logo"
|
||||||
import { pb } from "@/lib/stores"
|
import { pb } from "@/lib/stores"
|
||||||
import { cn, isReadOnlyUser, isAdmin } from "@/lib/utils"
|
import { cn, isReadOnlyUser, isAdmin, logOut } from "@/lib/utils"
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
@@ -99,7 +99,7 @@ export default function Navbar() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</DropdownMenuGroup>
|
</DropdownMenuGroup>
|
||||||
<DropdownMenuItem onSelect={() => pb.authStore.clear()}>
|
<DropdownMenuItem onSelect={logOut}>
|
||||||
<LogOutIcon className="me-2.5 h-4 w-4" />
|
<LogOutIcon className="me-2.5 h-4 w-4" />
|
||||||
<span>
|
<span>
|
||||||
<Trans>Log Out</Trans>
|
<Trans>Log Out</Trans>
|
||||||
|
@@ -33,7 +33,7 @@ const verifyAuth = () => {
|
|||||||
pb.collection("users")
|
pb.collection("users")
|
||||||
.authRefresh()
|
.authRefresh()
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
pb.authStore.clear()
|
logOut()
|
||||||
toast({
|
toast({
|
||||||
title: t`Failed to authenticate`,
|
title: t`Failed to authenticate`,
|
||||||
description: t`Please log in again`,
|
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 = () => {
|
export const updateAlerts = () => {
|
||||||
pb.collection("alerts")
|
pb.collection("alerts")
|
||||||
|
Reference in New Issue
Block a user