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

* feat: redirect authenticated users from signup page

- Add session check in signup getServerSideProps
- Redirect to redirect parameter if present, otherwise to root
- Follows existing authentication patterns in codebase

Co-Authored-By: peer@cal.com <peer@cal.com>

* fix test

* fix test

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: unknown <adhabal2002@gmail.com>
Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
This commit is contained in:
Peer Richelsen
2025-09-12 23:36:00 +05:30
committed by GitHub
co-authored by peer@cal.com Devin AI unknown Anik Dhabal Babu
parent 2be388373f
commit a63802dea7
2 changed files with 17 additions and 0 deletions
@@ -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,
@@ -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();