Skip to content

Commit 428d3e5

Browse files
committed
fix
1 parent 35ba82e commit 428d3e5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/app/(onboarding)/layout.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ export default async function OnboardingLayout({
1313
redirect("/signin");
1414
}
1515

16-
const workspaceId = session.user.workspaceId;
16+
// The session JWT may not yet reflect a workspace that was just linked.
17+
// Fall back to a direct DB lookup for email auth users.
18+
let workspaceId = session.user.workspaceId;
19+
20+
if (!workspaceId && session.user.authType === "email") {
21+
const dbUser = await prisma.user.findUnique({
22+
where: { id: session.user.id },
23+
select: { workspaceId: true },
24+
});
25+
workspaceId = dbUser?.workspaceId ?? undefined;
26+
}
1727

1828
if (workspaceId) {
1929
const workspace = await prisma.workspace.findUnique({

src/app/(onboarding)/onboarding/page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { auth } from "@/lib/auth";
22
import { redirect } from "next/navigation";
3+
import prisma from "@/lib/prisma";
34
import { OnboardingWizard } from "./onboarding-wizard";
45

56
export default async function OnboardingPage() {
@@ -9,11 +10,23 @@ export default async function OnboardingPage() {
910
redirect("/signin");
1011
}
1112

13+
// The session JWT may not yet reflect a workspace that was just linked
14+
// (e.g. after the Slack OAuth callback). Fall back to a direct DB lookup.
15+
let workspaceId = session.user.workspaceId;
16+
17+
if (!workspaceId && session.user.authType === "email") {
18+
const dbUser = await prisma.user.findUnique({
19+
where: { id: session.user.id },
20+
select: { workspaceId: true },
21+
});
22+
workspaceId = dbUser?.workspaceId ?? undefined;
23+
}
24+
1225
return (
1326
<OnboardingWizard
1427
authType={session.user.authType}
1528
userId={session.user.id}
16-
workspaceId={session.user.workspaceId}
29+
workspaceId={workspaceId}
1730
/>
1831
);
1932
}

0 commit comments

Comments
 (0)