Skip to content

Scheduling infrastructure for absolutely everyone.

feat: signup redirect query param after onboarding (#13761)

sean-brydon92286e2453c3
diff --git a/apps/web/components/getting-started/steps-views/UserProfile.tsx b/apps/web/components/getting-started/steps-views/UserProfile.tsx
index 84bb8d44c40..6cc5c5480dd 100644
--- a/apps/web/components/getting-started/steps-views/UserProfile.tsx
+++ b/apps/web/components/getting-started/steps-views/UserProfile.tsx
@@ -37,7 +37,7 @@ const UserProfile = () => {
if (context.avatar) {
showToast(t("your_user_profile_updated_successfully"), "success");
await utils.viewer.me.refetch();
- } else {
+ } else
try {
if (eventTypes?.length === 0) {
await Promise.all(
@@ -50,9 +50,11 @@ const UserProfile = () => {
console.error(error);
}
- await utils.viewer.me.refetch();
- router.push("/");
- }
+ await utils.viewer.me.refetch();
+ const redirectUrl = localStorage.getItem("onBoardingRedirect");
+ localStorage.removeItem("onBoardingRedirect");
+
+ redirectUrl ? router.push(redirectUrl) : router.push("/");
},
onError: () => {
showToast(t("problem_saving_user_profile"), "error");
diff --git a/apps/web/lib/signup/getServerSideProps.tsx b/apps/web/lib/signup/getServerSideProps.tsx
index 22a2149a9f0..0d2af88c794 100644
--- a/apps/web/lib/signup/getServerSideProps.tsx
+++ b/apps/web/lib/signup/getServerSideProps.tsx
@@ -27,8 +27,19 @@ export const getServerSideProps = async (ctx: GetServerSidePropsContext) => {
const signupDisabled = await getFeatureFlag(prisma, "disable-signup");
const ssr = await ssrInit(ctx);
const token = z.string().optional().parse(ctx.query.token);
+ const redirectUrlData = z
+ .string()
+ .refine((value) => value.startsWith(WEBAPP_URL), {
+ params: (value: string) => ({ value }),
+ message: "Redirect URL must start with 'cal.com'",
+ })
+ .optional()
+ .safeParse(ctx.query.redirect);
+
+ const redirectUrl = redirectUrlData.success ? redirectUrlData.data : undefined;
const props = {
+ redirectUrl,
isGoogleLoginEnabled: IS_GOOGLE_LOGIN_ENABLED,
isSAMLLoginEnabled,
trpcState: ssr.dehydrate(),
diff --git a/apps/web/pages/signup.tsx b/apps/web/pages/signup.tsx
index 4f9d6782ab5..67f9de99b69 100644
--- a/apps/web/pages/signup.tsx
+++ b/apps/web/pages/signup.tsx
@@ -159,6 +159,7 @@ export default function Signup({
isGoogleLoginEnabled,
isSAMLLoginEnabled,
orgAutoAcceptEmail,
+ redirectUrl,
}: SignupProps) {
const [premiumUsername, setPremiumUsername] = useState(false);
const [usernameTaken, setUsernameTaken] = useState(false);
@@ -180,6 +181,12 @@ export default function Signup({
formState: { isSubmitting, errors, isSubmitSuccessful },
} = formMethods;
+ useEffect(() => {
+ if (redirectUrl) {
+ localStorage.setItem("onBoardingRedirect", redirectUrl);
+ }
+ }, [redirectUrl]);
+
const loadingSubmitState = isSubmitSuccessful || isSubmitting;
const handleErrorsAndStripe = async (resp: Response) => {