From cc24f070db26337a4a2d87d68c7f142ed1118584 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Jun 2026 16:56:24 +0200 Subject: [PATCH] fix: redirect to login after credentials logout instead of crashing on current page (#5819) Co-authored-by: Thomas --- .../nextjs/src/app/[locale]/manage/users/[userId]/layout.tsx | 4 ++-- .../src/app/[locale]/manage/users/[userId]/security/page.tsx | 5 +++-- apps/nextjs/src/components/user-avatar-menu.tsx | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/layout.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/layout.tsx index e2a43ccef..2e5c426cb 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/layout.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/layout.tsx @@ -10,7 +10,7 @@ import { UserAvatar } from "@homarr/ui"; import { ManageContainer } from "~/components/manage/manage-container"; import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb"; -import { catchTrpcNotFound } from "~/errors/trpc-catch-error"; +import { catchTrpcNotFound, catchTrpcUnauthorized } from "~/errors/trpc-catch-error"; import { NavigationLink } from "../groups/[id]/_navigation"; import { canAccessUserEditPage } from "./access"; @@ -26,7 +26,7 @@ export default async function Layout(props: PropsWithChildren) { const session = await auth(); const t = await getI18n(); const tUser = await getScopedI18n("management.page.user"); - const user = await api.user.getById({ userId: params.userId }).catch(catchTrpcNotFound); + const user = await api.user.getById({ userId: params.userId }).catch(catchTrpcNotFound).catch(catchTrpcUnauthorized); if (!canAccessUserEditPage(session, user.id)) { notFound(); diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/security/page.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/security/page.tsx index f3098258b..cbd83c047 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/security/page.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/security/page.tsx @@ -5,7 +5,7 @@ import { api } from "@homarr/api/server"; import { auth } from "@homarr/auth/next"; import { getScopedI18n } from "@homarr/translation/server"; -import { catchTrpcNotFound } from "~/errors/trpc-catch-error"; +import { catchTrpcNotFound, catchTrpcUnauthorized } from "~/errors/trpc-catch-error"; import { canAccessUserEditPage } from "../access"; import { ChangePasswordForm } from "./_components/_change-password-form"; @@ -23,7 +23,8 @@ export default async function UserSecurityPage(props: Props) { .getById({ userId: params.userId, }) - .catch(catchTrpcNotFound); + .catch(catchTrpcNotFound) + .catch(catchTrpcUnauthorized); if (!canAccessUserEditPage(session, user.id)) { notFound(); diff --git a/apps/nextjs/src/components/user-avatar-menu.tsx b/apps/nextjs/src/components/user-avatar-menu.tsx index 8faa8f6fa..71ec2b218 100644 --- a/apps/nextjs/src/components/user-avatar-menu.tsx +++ b/apps/nextjs/src/components/user-avatar-menu.tsx @@ -45,7 +45,7 @@ export const UserAvatarMenu = ({ children, availableUpdatesPromise }: UserAvatar window.location.assign(logoutUrl); return; } - router.refresh(); + router.push("/auth/login"); }, }); }, [logoutUrl, openModal, router]);