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: [email protected] <[email protected]> * fix test * fix test --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: unknown <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
2 files changed
+17
No files matched your search
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user