Skip to content

Scheduling infrastructure for absolutely everyone.

refactor: Removed asStringOrNull functions (#25029)

Alex van Andeldb8c7942a937
diff --git a/apps/web/lib/asStringOrNull.tsx b/apps/web/lib/asStringOrNull.tsx
deleted file mode 100644
index 564075cd853..00000000000
--- a/apps/web/lib/asStringOrNull.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-/** @deprecated use zod instead */
-export function asStringOrNull(str: unknown) {
- return typeof str === "string" ? str : null;
-}
-
-/** @deprecated use zod instead */
-export function asStringOrUndefined(str: unknown) {
- return typeof str === "string" ? str : undefined;
-}
-
-/** @deprecated use zod instead */
-export function asNumberOrUndefined(str: unknown) {
- return typeof str === "string" ? parseInt(str) : undefined;
-}
-
-/** @deprecated use zod instead */
-export function asNumberOrThrow(str: unknown) {
- return parseInt(asStringOrThrow(str));
-}
-
-/** @deprecated use zod instead */
-export function asStringOrThrow(str: unknown): string {
- if (typeof str !== "string") {
- throw new Error(`Expected "string" - got ${typeof str}`);
- }
- return str;
-}
diff --git a/apps/web/server/lib/auth/sso/[provider]/getServerSideProps.tsx b/apps/web/server/lib/auth/sso/[provider]/getServerSideProps.tsx
index a4754549aa1..8dc8a6395d7 100644
--- a/apps/web/server/lib/auth/sso/[provider]/getServerSideProps.tsx
+++ b/apps/web/server/lib/auth/sso/[provider]/getServerSideProps.tsx
@@ -9,31 +9,31 @@ import { ssoTenantProduct } from "@calcom/features/ee/sso/lib/sso";
import { checkUsername } from "@calcom/features/profile/lib/checkUsername";
import { OnboardingPathService } from "@calcom/features/onboarding/lib/onboarding-path.service";
import { IS_PREMIUM_USERNAME_ENABLED } from "@calcom/lib/constants";
-import prisma from "@calcom/prisma";
+import { prisma } from "@calcom/prisma";
+import { z } from "zod";
-import { asStringOrNull } from "@lib/asStringOrNull";
+const Params = z.object({
+ username: z.string().optional(),
+ email: z.string().optional(),
+ provider: z.string({ required_error: "File is not named sso/[provider]" }),
+});
-export const getServerSideProps = async (context: GetServerSidePropsContext) => {
- // get query params and typecast them to string
- // (would be even better to assert them instead of typecasting)
- const providerParam = asStringOrNull(context.query.provider);
- const emailParam = asStringOrNull(context.query.email);
- const usernameParam = asStringOrNull(context.query.username);
+export const getServerSideProps = async ({ req, query }: GetServerSidePropsContext) => {
+
+ const {
+ provider: providerParam,
+ email: emailParam,
+ username: usernameParam,
+ } = Params.parse(query);
const successDestination = await OnboardingPathService.getGettingStartedPathWithParams(
prisma,
usernameParam ? { username: usernameParam } : undefined
);
- if (!providerParam) {
- throw new Error(`File is not named sso/[provider]`);
- }
-
- const { req } = context;
-
const session = await getServerSession({ req });
- const { currentOrgDomain } = orgDomainConfig(context.req);
+ const { currentOrgDomain } = orgDomainConfig(req);
if (session) {
// Validating if username is Premium, while this is true an email its required for stripe user confirmation