From 255ba197664d7beaff68df415dae054d59fb760e Mon Sep 17 00:00:00 2001 From: Giancarlo Buomprisco Date: Fri, 23 Jan 2026 11:12:49 +0100 Subject: [PATCH] chore: bump version to 2.23.10 and enhance workspace loading logic (#447) * chore: bump version to 2.23.10 and enhance workspace loading logic - Updated application version from 2.23.9 to 2.23.10 in package.json. - Refactored workspace loading functions to use async/await for improved error handling and added redirects for missing workspaces or users. - Updated sidebar layout components to handle asynchronous data fetching and redirection more effectively. - Minor adjustments to personal account dropdown styles for consistency. --- .../home/(user)/_lib/server/load-user-workspace.ts | 7 +++++++ apps/web/app/home/(user)/layout.tsx | 13 ++++++++++--- apps/web/app/home/[account]/layout.tsx | 13 ++++++++++--- package.json | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/apps/web/app/home/(user)/_lib/server/load-user-workspace.ts b/apps/web/app/home/(user)/_lib/server/load-user-workspace.ts index 78172304c..c39a496b9 100644 --- a/apps/web/app/home/(user)/_lib/server/load-user-workspace.ts +++ b/apps/web/app/home/(user)/_lib/server/load-user-workspace.ts @@ -1,5 +1,7 @@ import { cache } from 'react'; +import { redirect } from 'next/navigation'; + import { createAccountsApi } from '@kit/accounts/api'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { createAccountCreationPolicyEvaluator } from '@kit/team-accounts/policies'; @@ -35,6 +37,11 @@ async function workspaceLoader() { requireUserInServerComponent(), ]); + // If the user is not found or the workspace is not found, redirect to the home page - this may happen if the JWT is invalid or expired (ex. user deleted?) + if (!workspace || !user) { + redirect('/'); + } + // Check if user can create team accounts (policy check) const canCreateTeamAccount = shouldLoadAccounts ? await checkCanCreateTeamAccount(user.id) diff --git a/apps/web/app/home/(user)/layout.tsx b/apps/web/app/home/(user)/layout.tsx index 6ede44705..3af422bb0 100644 --- a/apps/web/app/home/(user)/layout.tsx +++ b/apps/web/app/home/(user)/layout.tsx @@ -1,6 +1,7 @@ import { use } from 'react'; import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; import { z } from 'zod'; @@ -30,9 +31,15 @@ function UserHomeLayout({ children }: React.PropsWithChildren) { export default withI18n(UserHomeLayout); -function SidebarLayout({ children }: React.PropsWithChildren) { - const workspace = use(loadUserWorkspace()); - const state = use(getLayoutState()); +async function SidebarLayout({ children }: React.PropsWithChildren) { + const [workspace, state] = await Promise.all([ + loadUserWorkspace().catch(() => null), + getLayoutState(), + ]); + + if (!workspace) { + redirect('/'); + } return ( diff --git a/apps/web/app/home/[account]/layout.tsx b/apps/web/app/home/[account]/layout.tsx index ffefb5f7c..dd6fcb897 100644 --- a/apps/web/app/home/[account]/layout.tsx +++ b/apps/web/app/home/[account]/layout.tsx @@ -1,6 +1,7 @@ import { use } from 'react'; import { cookies } from 'next/headers'; +import { redirect } from 'next/navigation'; import { z } from 'zod'; @@ -33,14 +34,20 @@ function TeamWorkspaceLayout({ children, params }: TeamWorkspaceLayoutProps) { return {children}; } -function SidebarLayout({ +async function SidebarLayout({ account, children, }: React.PropsWithChildren<{ account: string; }>) { - const data = use(loadTeamWorkspace(account)); - const state = use(getLayoutState(account)); + const [data, state] = await Promise.all([ + loadTeamWorkspace(account), + getLayoutState(account), + ]); + + if (!data) { + redirect('/'); + } const accounts = data.accounts.map(({ name, slug, picture_url }) => ({ label: name, diff --git a/package.json b/package.json index a1c15a232..2f67a0102 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-supabase-saas-kit-turbo", - "version": "2.23.9", + "version": "2.23.10", "private": true, "sideEffects": false, "engines": {