diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-09-14 11:57:11 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-09-14 11:57:11 +0000 |
| commit | 92e357f141ff2aa4730e4a6ec316b7524fec863a (patch) | |
| tree | 444ce72098b87b45399fd548c61be265c1ca884e /apps | |
| parent | d53b28261cecdb093128f59acf15af3e7919d3ca (diff) | |
| download | karakeep-92e357f141ff2aa4730e4a6ec316b7524fec863a.tar.zst | |
fix(web): Handle user deletion more gracefully
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/web/app/dashboard/layout.tsx | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/apps/web/app/dashboard/layout.tsx b/apps/web/app/dashboard/layout.tsx index 1471bfde..911d542c 100644 --- a/apps/web/app/dashboard/layout.tsx +++ b/apps/web/app/dashboard/layout.tsx @@ -7,6 +7,7 @@ import { Separator } from "@/components/ui/separator"; import { UserSettingsContextProvider } from "@/lib/userSettings"; import { api } from "@/server/api/client"; import { getServerAuthSession } from "@/server/auth"; +import { TRPCError } from "@trpc/server"; import { TFunction } from "i18next"; import { Archive, @@ -18,6 +19,7 @@ import { } from "lucide-react"; import { PluginManager, PluginType } from "@karakeep/shared/plugins"; +import { tryCatch } from "@karakeep/shared/tryCatch"; export default async function Dashboard({ children, @@ -32,10 +34,26 @@ export default async function Dashboard({ } const [lists, userSettings] = await Promise.all([ - api.lists.list(), - api.users.settings(), + tryCatch(api.lists.list()), + tryCatch(api.users.settings()), ]); + if (userSettings.error) { + if (userSettings.error instanceof TRPCError) { + if ( + userSettings.error.code === "NOT_FOUND" || + userSettings.error.code === "UNAUTHORIZED" + ) { + redirect("/logout"); + } + } + throw userSettings.error; + } + + if (lists.error) { + throw lists.error; + } + const items = (t: TFunction) => [ { @@ -79,7 +97,7 @@ export default async function Dashboard({ ]; return ( - <UserSettingsContextProvider userSettings={userSettings}> + <UserSettingsContextProvider userSettings={userSettings.data}> <SidebarLayout sidebar={ <Sidebar @@ -87,7 +105,7 @@ export default async function Dashboard({ extraSections={ <> <Separator /> - <AllLists initialData={lists} /> + <AllLists initialData={lists.data} /> </> } /> |
