|
1 | 1 | import { redirect } from 'next/navigation' |
2 | | -import { getSession } from '@/lib/auth' |
3 | 2 | import { isChatEnabled } from '@/lib/core/config/env-flags' |
4 | | -import { getFirstWorkflowIdForWorkspace } from '@/lib/workflows/queries' |
5 | | -import { getWorkspaceHostContextForViewer } from '@/lib/workspaces/host-context' |
6 | 3 |
|
7 | 4 | /** |
8 | 5 | * Resolves the workspace landing route. With Chat enabled that is the chat |
9 | | - * composer; otherwise it is the workspace's first workflow, resolved here so the |
10 | | - * browser makes a single server redirect instead of bouncing through `/w`, which |
11 | | - * would mount a client component and flash a spinner before redirecting again. |
| 6 | + * composer; otherwise `/w`, which selects the first workflow from the workflow |
| 7 | + * list the layout already prefetched. |
12 | 8 | * |
13 | | - * Access is checked before resolving: this page and the layout render |
14 | | - * concurrently, so redirecting first would put a real workflow id in a |
15 | | - * non-member's URL bar and history before the layout denies them. `getSession` |
16 | | - * and `getWorkspaceHostContextForViewer` are both request-memoized, so the |
17 | | - * checks are shared with the layout rather than duplicated. |
| 9 | + * Deliberately does no work of its own. Resolving the workflow here would mean |
| 10 | + * a session lookup, an access check, and a query before anything renders — and |
| 11 | + * a slow database would leave the user on a blank page instead of a redirect, |
| 12 | + * since there is nothing to show until all three finish. |
18 | 13 | */ |
19 | 14 | export default async function WorkspacePage({ |
20 | 15 | params, |
21 | 16 | }: { |
22 | 17 | params: Promise<{ workspaceId: string }> |
23 | 18 | }) { |
24 | 19 | const { workspaceId } = await params |
25 | | - |
26 | | - if (isChatEnabled) { |
27 | | - redirect(`/workspace/${workspaceId}/home`) |
28 | | - } |
29 | | - |
30 | | - const session = await getSession() |
31 | | - if (!session?.user) { |
32 | | - redirect('/login') |
33 | | - } |
34 | | - |
35 | | - const hostContext = await getWorkspaceHostContextForViewer(workspaceId, session.user.id) |
36 | | - if (!hostContext) { |
37 | | - // The layout renders WorkspaceAccessDenied for this case. |
38 | | - return null |
39 | | - } |
40 | | - |
41 | | - const workflowId = await getFirstWorkflowIdForWorkspace(workspaceId) |
42 | | - redirect(workflowId ? `/workspace/${workspaceId}/w/${workflowId}` : `/workspace/${workspaceId}/w`) |
| 20 | + redirect(`/workspace/${workspaceId}/${isChatEnabled ? 'home' : 'w'}`) |
43 | 21 | } |
0 commit comments