chore: Implement onboarding redirect logic in event-types and main page components (#24785)
## What does this PR do? Currently we load /event-types for a few seconds while the onboarding hook catches up. This adds that logic to the serverside and not just client side to ensure onboarding is triggered Adds server-side onboarding redirect checks to prevent users from accessing event types pages before completing onboarding. This implementation: - Creates a new `checkOnboardingRedirect` utility function in a dedicated file - Applies the redirect check on both the root page and event-types page - Optimizes performance by using organizationId from session when available - Handles email verification requirements before redirecting to onboarding - Supports both legacy and v3 onboarding paths based on feature flags ## How should this be tested? - Create a new user account that hasn't completed onboarding - Attempt to access the root page or event-types page directly - Verify you're redirected to the appropriate onboarding flow - Test with email verification feature flag enabled/disabled - Test with onboarding-v3 feature flag enabled/disabled - Verify users who have completed onboarding can access event-types normally - Verify organization users aren't redirected to onboarding ## Video Demo Before: [CleanShot 2025-10-30 at 10.54.41.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/user-attachments/thumbnails/8282decc-a00d-4bc8-9215-fe1c4809fd8f.mp4" />](https://app.graphite.dev/user-attachments/video/8282decc-a00d-4bc8-9215-fe1c4809fd8f.mp4) After ## [CleanShot 2025-10-30 at 10.54.06.mp4 <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/user-attachments/thumbnails/2acc7601-6c8c-496a-af4d-08dadef9aa2d.mp4" />](https://app.graphite.dev/user-attachments/video/2acc7601-6c8c-496a-af4d-08dadef9aa2d.mp4) ## Checklist - [x] I have self-reviewed the code - [x] I have updated the developer docs in /docs if this PR makes changes that would require a documentation change - [x] I confirm automated tests are in place that prove my fix is effective or that my feature works
This commit is contained in:
1 parent
1c2da58d2a
commit
6cbe1c1cf1
3 files changed
+92
No files matched your search
@@ -6,6 +6,7 @@ import { unstable_cache } from "next/cache";
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { checkOnboardingRedirect } from "@calcom/features/auth/lib/onboardingUtils";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
|
||||
import { eventTypesRouter } from "@calcom/trpc/server/routers/viewer/eventTypes/_router";
|
||||
@@ -53,6 +54,17 @@ const Page = async ({ searchParams }: PageProps) => {
|
||||
return redirect("/auth/login");
|
||||
}
|
||||
|
||||
// Check if user needs onboarding and redirect before fetching event types data
|
||||
// Use organizationId from session profile if available to avoid extra query
|
||||
const organizationId = session.user.profile?.organizationId ?? null;
|
||||
const onboardingPath = await checkOnboardingRedirect(session.user.id, {
|
||||
checkEmailVerification: true,
|
||||
organizationId,
|
||||
});
|
||||
if (onboardingPath) {
|
||||
return redirect(onboardingPath);
|
||||
}
|
||||
|
||||
const t = await getTranslate();
|
||||
const filters = getTeamsFiltersFromQuery(_searchParams);
|
||||
const userEventGroupsData = await getCachedEventGroups(_headers, _cookies, filters);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { cookies, headers } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { checkOnboardingRedirect } from "@calcom/features/auth/lib/onboardingUtils";
|
||||
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
|
||||
|
||||
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
|
||||
@@ -11,6 +12,17 @@ const RedirectPage = async () => {
|
||||
if (!session?.user?.id) {
|
||||
redirect("/auth/login");
|
||||
}
|
||||
|
||||
// Check if user needs onboarding and redirect before going to event-types
|
||||
const organizationId = session.user.profile?.organizationId ?? null;
|
||||
const onboardingPath = await checkOnboardingRedirect(session.user.id, {
|
||||
checkEmailVerification: true,
|
||||
organizationId,
|
||||
});
|
||||
if (onboardingPath) {
|
||||
redirect(onboardingPath);
|
||||
}
|
||||
|
||||
redirect("/event-types");
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user