Skip to content

Scheduling infrastructure for absolutely everyone.

feat: redirect authenticated users from signup page (#23766)

Peer Richelsena63802dea7d2
diff --git a/apps/web/lib/signup/getServerSideProps.tsx b/apps/web/lib/signup/getServerSideProps.tsx
index 8960cdd652d..3111101f53a 100644
--- a/apps/web/lib/signup/getServerSideProps.tsx
+++ b/apps/web/lib/signup/getServerSideProps.tsx
@@ -1,6 +1,7 @@
import type { GetServerSidePropsContext } from "next";
import { z } from "zod";
+import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { getOrgUsernameFromEmail } from "@calcom/features/auth/signup/utils/getOrgUsernameFromEmail";
import { checkPremiumUsername } from "@calcom/features/ee/common/lib/checkPremiumUsername";
import { isSAMLLoginEnabled } from "@calcom/features/ee/sso/lib/saml";
@@ -42,6 +43,19 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
const redirectUrl = redirectUrlData.success && redirectUrlData.data ? redirectUrlData.data : null;
+ const session = await getServerSession({
+ req: ctx.req,
+ });
+
+ if (session?.user?.id) {
+ return {
+ redirect: {
+ permanent: false,
+ destination: redirectUrl || "/",
+ },
+ } as const;
+ }
+
const props = {
redirectUrl,
isGoogleLoginEnabled: IS_GOOGLE_LOGIN_ENABLED,
diff --git a/apps/web/playwright/organization/organization-invitation.e2e.ts b/apps/web/playwright/organization/organization-invitation.e2e.ts
index 79174a05cc6..154bd1eeffb 100644
--- a/apps/web/playwright/organization/organization-invitation.e2e.ts
+++ b/apps/web/playwright/organization/organization-invitation.e2e.ts
@@ -304,6 +304,9 @@ test.describe("Organization", () => {
});
await test.step("Signing up with the previous username of the migrated user - shouldn't be allowed", async () => {
+ await orgOwner.logout();
+ await page.goto("/");
+ await page.waitForLoadState();
await page.goto("/signup");
await expect(page.locator("text=Create your account")).toBeVisible();
await expect(page.locator('[data-testid="continue-with-email-button"]')).toBeVisible();