* create StripeRepository and simplify code * verify-email-change: extract getServerSideProps * add verify-email-change to app router * auth/verify: Add metadata in app router * auth/verify: extract client component into /modules * fix type checks for stripe * fix stripe session handler * improve getServerSideProps for verify-email-change * add title to verify-email-change page metadata * add title to verify page metadata * refactor * add safety * fix * remove references to pages for verify-email --------- Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com>
53 lines
997 B
TypeScript
53 lines
997 B
TypeScript
import type { GetServerSidePropsContext } from "next";
|
|
import { z } from "zod";
|
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
|
|
const tokenSchema = z.object({
|
|
token: z.string(),
|
|
});
|
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
|
const parsed = tokenSchema.safeParse(context.query);
|
|
if (!parsed.success) {
|
|
return {
|
|
notFound: true,
|
|
} as const;
|
|
}
|
|
const { token } = parsed.data;
|
|
|
|
if (!token) {
|
|
return {
|
|
notFound: true,
|
|
} as const;
|
|
}
|
|
|
|
const params = new URLSearchParams({
|
|
token,
|
|
});
|
|
|
|
const response = await fetch(`${WEBAPP_URL}/api/auth/verify-email?${params.toString()}`, {
|
|
method: "POST",
|
|
});
|
|
|
|
if (!response.ok) {
|
|
return {
|
|
props: {
|
|
updateSession: false,
|
|
token,
|
|
updatedEmail: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
return {
|
|
props: {
|
|
updateSession: true,
|
|
token,
|
|
updatedEmail: data.updatedEmail ?? null,
|
|
},
|
|
};
|
|
}
|