fix: align board page and metadata error handling with layout

- resolve the session before handling board lookup errors so anonymous
  users still get the /auth/login redirect on a missing home board
- map both NOT_FOUND and BAD_REQUEST to a 404 in the board page and in
  generateMetadataAsync, matching the layout behavior
- clarify the getAvailability MCP description to mention demo-mode
  availability
This commit is contained in:
Thomas Camlong committed 2026-08-06 13:32:52 +02:00
1 parent f61e3591bd
commit 974dc1609c
2 files changed
+24 -12

No files matched your search

@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import { Suspense } from "react";
import { notFound } from "next/navigation";
import { notFound, redirect } from "next/navigation";
import { TRPCError } from "@trpc/server";
// Placed here because gridstack styles are used for board content
@@ -50,16 +50,24 @@ export const createBoardContentPage = <TParams extends Record<string, unknown>>(
page: async ({ params }: { params: Promise<TParams> }) => {
const resolvedParams = await params;
const queryClient = getQueryClient();
const session = await auth();
const [board, session] = await Promise.all([
getInitialBoard(resolvedParams).catch((error) => {
if (error instanceof TRPCError && (error.code === "NOT_FOUND" || error.code === "BAD_REQUEST")) {
notFound();
const board = await getInitialBoard(resolvedParams).catch((error) => {
if (error instanceof TRPCError && error.code === "NOT_FOUND") {
if (!session) {
logger.debug("No home board found for anonymous user, redirecting to login");
redirect("/auth/login");
}
throw error;
}),
auth(),
]);
notFound();
}
if (error instanceof TRPCError && error.code === "BAD_REQUEST") {
notFound();
}
throw error;
});
const itemsMap = board.items.reduce((acc, item) => {
const existing = acc.get(item.kind);
@@ -119,8 +127,11 @@ export const createBoardContentPage = <TParams extends Record<string, unknown>>(
},
};
} catch (error) {
// Ignore not found errors and return empty metadata
if (error instanceof TRPCError && error.code === "NOT_FOUND") {
// Ignore not found and bad-request errors and return empty metadata
if (
error instanceof TRPCError &&
(error.code === "NOT_FOUND" || error.code === "BAD_REQUEST")
) {
return {};
}
+2 -1
View File
@@ -444,7 +444,8 @@ export const assistantRouter = createTRPCRouter({
.meta({
mcp: {
enabled: true,
description: "Check whether Homarr Assistant is enabled and configured for the current user",
description:
"Check whether Homarr Assistant is enabled and configured, or available in demo mode, for the current user",
},
})
.query(async ({ ctx }) => {