refactor: Removed asStringOrNull functions (#25029)
This commit is contained in:
1 parent
4e5d4f67d5
commit
db8c7942a9
2 files changed
+15
-42
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user