From 861931f68f1370a83bc4ee0fdde6739386393a25 Mon Sep 17 00:00:00 2001 From: Dmytro Hryshyn Date: Tue, 9 Jan 2024 13:04:51 +0200 Subject: [PATCH 1/8] wip --- apps/web/pages/d/[link]/[slug].tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/pages/d/[link]/[slug].tsx b/apps/web/pages/d/[link]/[slug].tsx index 8a52eff77d3a0d..709527beb24ca9 100644 --- a/apps/web/pages/d/[link]/[slug].tsx +++ b/apps/web/pages/d/[link]/[slug].tsx @@ -1,4 +1,3 @@ -"use client"; import { Booker } from "@calcom/atoms"; import { getBookerWrapperClasses } from "@calcom/features/bookings/Booker/utils/getBookerWrapperClasses"; From c4b8318b1419e9e174c5ac00905cdc92d6e19d7c Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Thu, 11 Jan 2024 01:46:12 +0100 Subject: [PATCH 2/8] chore: forgot password page migration --- .../future/auth/forgot-password/[id]/page.tsx | 19 +++++++++ .../app/future/auth/forgot-password/page.tsx | 19 +++++++++ apps/web/pages/auth/forgot-password/[id].tsx | 40 ++----------------- apps/web/pages/auth/forgot-password/index.tsx | 30 ++------------ apps/web/server/lib/forgotPasswordGetData.tsx | 27 +++++++++++++ .../lib/forgotPasswordWithIdGetData.tsx | 37 +++++++++++++++++ 6 files changed, 110 insertions(+), 62 deletions(-) create mode 100644 apps/web/app/future/auth/forgot-password/[id]/page.tsx create mode 100644 apps/web/app/future/auth/forgot-password/page.tsx create mode 100644 apps/web/server/lib/forgotPasswordGetData.tsx create mode 100644 apps/web/server/lib/forgotPasswordWithIdGetData.tsx diff --git a/apps/web/app/future/auth/forgot-password/[id]/page.tsx b/apps/web/app/future/auth/forgot-password/[id]/page.tsx new file mode 100644 index 00000000000000..e14032a4c74e5f --- /dev/null +++ b/apps/web/app/future/auth/forgot-password/[id]/page.tsx @@ -0,0 +1,19 @@ +import SetNewUserPassword from "@pages/auth/forgot-password/[id]"; +import { withAppDir } from "app/AppDirSSRHOC"; +import { _generateMetadata } from "app/_utils"; +import { WithLayout } from "app/layoutHOC"; + +import { getForgotPasswordWithIdPageData } from "@server/lib/forgotPasswordWithIdGetData"; + +export const generateMetadata = async () => { + return await _generateMetadata( + (t) => t("reset_password"), + (t) => t("change_your_password") + ); +}; + +export default WithLayout({ + getLayout: null, + Page: SetNewUserPassword, + getData: withAppDir(getForgotPasswordWithIdPageData), +})<"P">; diff --git a/apps/web/app/future/auth/forgot-password/page.tsx b/apps/web/app/future/auth/forgot-password/page.tsx new file mode 100644 index 00000000000000..a0fc2a7b64cba6 --- /dev/null +++ b/apps/web/app/future/auth/forgot-password/page.tsx @@ -0,0 +1,19 @@ +import ForgotPassword from "@pages/auth/forgot-password"; +import { withAppDir } from "app/AppDirSSRHOC"; +import { _generateMetadata } from "app/_utils"; +import { WithLayout } from "app/layoutHOC"; + +import { getForgotPasswordPageData } from "@server/lib/forgotPasswordGetData"; + +export const generateMetadata = async () => { + return await _generateMetadata( + (t) => t("reset_password"), + (t) => t("change_your_password") + ); +}; + +export default WithLayout({ + getLayout: null, + Page: ForgotPassword, + getData: withAppDir(getForgotPasswordPageData), +})<"P">; diff --git a/apps/web/pages/auth/forgot-password/[id].tsx b/apps/web/pages/auth/forgot-password/[id].tsx index 4bbb7e6a8c8523..ae2ffe7a7c5ed1 100644 --- a/apps/web/pages/auth/forgot-password/[id].tsx +++ b/apps/web/pages/auth/forgot-password/[id].tsx @@ -1,22 +1,19 @@ -import type { GetServerSidePropsContext } from "next"; -import { getCsrfToken } from "next-auth/react"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Link from "next/link"; import type { CSSProperties } from "react"; import { useForm } from "react-hook-form"; -import { getLocale } from "@calcom/features/auth/lib/getLocale"; import { useLocale } from "@calcom/lib/hooks/useLocale"; -import prisma from "@calcom/prisma"; import { Button, PasswordField, Form } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; +import { getForgotPasswordWithIdPageData } from "@server/lib/forgotPasswordWithIdGetData"; + type Props = { requestId: string; isRequestExpired: boolean; - csrfToken: string; + csrfToken: string | undefined; }; export default function Page({ requestId, isRequestExpired, csrfToken }: Props) { @@ -143,33 +140,4 @@ export default function Page({ requestId, isRequestExpired, csrfToken }: Props) } Page.PageWrapper = PageWrapper; -export async function getServerSideProps(context: GetServerSidePropsContext) { - const id = context.params?.id as string; - - let resetPasswordRequest = await prisma.resetPasswordRequest.findFirst({ - where: { - id, - expires: { - gt: new Date(), - }, - }, - select: { - email: true, - }, - }); - try { - resetPasswordRequest && - (await prisma.user.findUniqueOrThrow({ where: { email: resetPasswordRequest.email } })); - } catch (e) { - resetPasswordRequest = null; - } - const locale = await getLocale(context.req); - return { - props: { - isRequestExpired: !resetPasswordRequest, - requestId: id, - csrfToken: await getCsrfToken({ req: context.req }), - ...(await serverSideTranslations(locale, ["common"])), - }, - }; -} +export const getServerSideProps = getForgotPasswordWithIdPageData; diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index 6e7df248409196..73d274d6eaf51b 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -1,21 +1,18 @@ // eslint-disable-next-line no-restricted-imports import { debounce } from "lodash"; -import type { GetServerSidePropsContext } from "next"; -import { getCsrfToken } from "next-auth/react"; -import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import Link from "next/link"; import type { CSSProperties, SyntheticEvent } from "react"; import React from "react"; -import { getLocale } from "@calcom/features/auth/lib/getLocale"; -import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Button, EmailField } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; -export default function ForgotPassword({ csrfToken }: { csrfToken: string }) { +import { getForgotPasswordPageData } from "@server/lib/forgotPasswordGetData"; + +export default function ForgotPassword({ csrfToken }: { csrfToken: string | undefined }) { const { t } = useLocale(); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState<{ message: string } | null>(null); @@ -145,23 +142,4 @@ export default function ForgotPassword({ csrfToken }: { csrfToken: string }) { ForgotPassword.PageWrapper = PageWrapper; -export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const { req, res } = context; - - const session = await getServerSession({ req }); - - // @TODO res will not be available in future pages (app dir) - if (session) { - res.writeHead(302, { Location: "/" }); - res.end(); - return { props: {} }; - } - const locale = await getLocale(context.req); - - return { - props: { - csrfToken: await getCsrfToken(context), - ...(await serverSideTranslations(locale, ["common"])), - }, - }; -}; +export const getServerSideProps = getForgotPasswordPageData; diff --git a/apps/web/server/lib/forgotPasswordGetData.tsx b/apps/web/server/lib/forgotPasswordGetData.tsx new file mode 100644 index 00000000000000..965cb68a22468f --- /dev/null +++ b/apps/web/server/lib/forgotPasswordGetData.tsx @@ -0,0 +1,27 @@ +import type { GetServerSidePropsContext } from "next"; +import { getCsrfToken } from "next-auth/react"; +import { serverSideTranslations } from "next-i18next/serverSideTranslations"; + +import { getLocale } from "@calcom/features/auth/lib/getLocale"; +import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; + +export async function getForgotPasswordPageData(context: GetServerSidePropsContext) { + const { req, res } = context; + + const session = await getServerSession({ req }); + + // @TODO res will not be available in future pages (app dir) + if (session) { + res.writeHead(302, { Location: "/" }); + res.end(); + return { props: {} }; + } + const locale = await getLocale(context.req); + + return { + props: { + csrfToken: await getCsrfToken(context), + ...(await serverSideTranslations(locale, ["common"])), + }, + }; +} diff --git a/apps/web/server/lib/forgotPasswordWithIdGetData.tsx b/apps/web/server/lib/forgotPasswordWithIdGetData.tsx new file mode 100644 index 00000000000000..2a698a4b4acf7c --- /dev/null +++ b/apps/web/server/lib/forgotPasswordWithIdGetData.tsx @@ -0,0 +1,37 @@ +import type { GetServerSidePropsContext } from "next"; +import { getCsrfToken } from "next-auth/react"; +import { serverSideTranslations } from "next-i18next/serverSideTranslations"; + +import { getLocale } from "@calcom/features/auth/lib/getLocale"; +import prisma from "@calcom/prisma"; + +export async function getForgotPasswordWithIdPageData(context: GetServerSidePropsContext) { + const id = context.params?.id as string; + + let resetPasswordRequest = await prisma.resetPasswordRequest.findFirst({ + where: { + id, + expires: { + gt: new Date(), + }, + }, + select: { + email: true, + }, + }); + try { + resetPasswordRequest && + (await prisma.user.findUniqueOrThrow({ where: { email: resetPasswordRequest.email } })); + } catch (e) { + resetPasswordRequest = null; + } + const locale = await getLocale(context.req); + return { + props: { + isRequestExpired: !resetPasswordRequest, + requestId: id, + csrfToken: await getCsrfToken({ req: context.req }), + ...(await serverSideTranslations(locale, ["common"])), + }, + }; +} From f03c71f9d6be6b3f5a732331264048cf25efe94f Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Thu, 11 Jan 2024 14:51:22 +0100 Subject: [PATCH 3/8] fix: conventions --- apps/web/app/future/auth/forgot-password/[id]/page.tsx | 4 ++-- apps/web/app/future/auth/forgot-password/page.tsx | 4 ++-- apps/web/pages/auth/forgot-password/[id].tsx | 4 ++-- apps/web/pages/auth/forgot-password/index.tsx | 4 ++-- apps/web/server/lib/forgotPasswordGetData.tsx | 2 +- apps/web/server/lib/forgotPasswordWithIdGetData.tsx | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/app/future/auth/forgot-password/[id]/page.tsx b/apps/web/app/future/auth/forgot-password/[id]/page.tsx index e14032a4c74e5f..a6618f3fe319c7 100644 --- a/apps/web/app/future/auth/forgot-password/[id]/page.tsx +++ b/apps/web/app/future/auth/forgot-password/[id]/page.tsx @@ -3,7 +3,7 @@ import { withAppDir } from "app/AppDirSSRHOC"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; -import { getForgotPasswordWithIdPageData } from "@server/lib/forgotPasswordWithIdGetData"; +import { getServerSideProps } from "@server/lib/forgotPasswordWithIdGetData"; export const generateMetadata = async () => { return await _generateMetadata( @@ -15,5 +15,5 @@ export const generateMetadata = async () => { export default WithLayout({ getLayout: null, Page: SetNewUserPassword, - getData: withAppDir(getForgotPasswordWithIdPageData), + getData: withAppDir(getServerSideProps), })<"P">; diff --git a/apps/web/app/future/auth/forgot-password/page.tsx b/apps/web/app/future/auth/forgot-password/page.tsx index a0fc2a7b64cba6..d65693791cb9c2 100644 --- a/apps/web/app/future/auth/forgot-password/page.tsx +++ b/apps/web/app/future/auth/forgot-password/page.tsx @@ -3,7 +3,7 @@ import { withAppDir } from "app/AppDirSSRHOC"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; -import { getForgotPasswordPageData } from "@server/lib/forgotPasswordGetData"; +import { getServerSideProps } from "@server/lib/forgotPasswordGetData"; export const generateMetadata = async () => { return await _generateMetadata( @@ -15,5 +15,5 @@ export const generateMetadata = async () => { export default WithLayout({ getLayout: null, Page: ForgotPassword, - getData: withAppDir(getForgotPasswordPageData), + getData: withAppDir(getServerSideProps), })<"P">; diff --git a/apps/web/pages/auth/forgot-password/[id].tsx b/apps/web/pages/auth/forgot-password/[id].tsx index ae2ffe7a7c5ed1..6d5ea6a664ed24 100644 --- a/apps/web/pages/auth/forgot-password/[id].tsx +++ b/apps/web/pages/auth/forgot-password/[id].tsx @@ -8,7 +8,7 @@ import { Button, PasswordField, Form } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; -import { getForgotPasswordWithIdPageData } from "@server/lib/forgotPasswordWithIdGetData"; +import { getServerSideProps } from "@server/lib/forgotPasswordWithIdGetData"; type Props = { requestId: string; @@ -140,4 +140,4 @@ export default function Page({ requestId, isRequestExpired, csrfToken }: Props) } Page.PageWrapper = PageWrapper; -export const getServerSideProps = getForgotPasswordWithIdPageData; +export { getServerSideProps }; diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index 73d274d6eaf51b..031bbe31c76282 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -10,7 +10,7 @@ import { Button, EmailField } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; -import { getForgotPasswordPageData } from "@server/lib/forgotPasswordGetData"; +import { getServerSideProps } from "@server/lib/forgotPasswordGetData"; export default function ForgotPassword({ csrfToken }: { csrfToken: string | undefined }) { const { t } = useLocale(); @@ -142,4 +142,4 @@ export default function ForgotPassword({ csrfToken }: { csrfToken: string | unde ForgotPassword.PageWrapper = PageWrapper; -export const getServerSideProps = getForgotPasswordPageData; +export { getServerSideProps }; diff --git a/apps/web/server/lib/forgotPasswordGetData.tsx b/apps/web/server/lib/forgotPasswordGetData.tsx index 965cb68a22468f..5c7faca87325bb 100644 --- a/apps/web/server/lib/forgotPasswordGetData.tsx +++ b/apps/web/server/lib/forgotPasswordGetData.tsx @@ -5,7 +5,7 @@ import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getLocale } from "@calcom/features/auth/lib/getLocale"; import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; -export async function getForgotPasswordPageData(context: GetServerSidePropsContext) { +export async function getServerSideProps(context: GetServerSidePropsContext) { const { req, res } = context; const session = await getServerSession({ req }); diff --git a/apps/web/server/lib/forgotPasswordWithIdGetData.tsx b/apps/web/server/lib/forgotPasswordWithIdGetData.tsx index 2a698a4b4acf7c..0ae3cf190611d4 100644 --- a/apps/web/server/lib/forgotPasswordWithIdGetData.tsx +++ b/apps/web/server/lib/forgotPasswordWithIdGetData.tsx @@ -5,7 +5,7 @@ import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import { getLocale } from "@calcom/features/auth/lib/getLocale"; import prisma from "@calcom/prisma"; -export async function getForgotPasswordWithIdPageData(context: GetServerSidePropsContext) { +export async function getServerSideProps(context: GetServerSidePropsContext) { const id = context.params?.id as string; let resetPasswordRequest = await prisma.resetPasswordRequest.findFirst({ From 5d417422addacdc8d12628e6a90fc307f40a91fb Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Thu, 11 Jan 2024 18:27:11 +0100 Subject: [PATCH 4/8] fix: convention --- apps/web/app/future/auth/forgot-password/[id]/page.tsx | 2 +- apps/web/app/future/auth/forgot-password/page.tsx | 2 +- apps/web/pages/auth/forgot-password/[id].tsx | 2 +- apps/web/pages/auth/forgot-password/index.tsx | 2 +- .../[id]/getServerSideProps.tsx} | 0 .../getServerSideProps.tsx} | 0 6 files changed, 4 insertions(+), 4 deletions(-) rename apps/web/server/lib/{forgotPasswordWithIdGetData.tsx => forgot-password/[id]/getServerSideProps.tsx} (100%) rename apps/web/server/lib/{forgotPasswordGetData.tsx => forgot-password/getServerSideProps.tsx} (100%) diff --git a/apps/web/app/future/auth/forgot-password/[id]/page.tsx b/apps/web/app/future/auth/forgot-password/[id]/page.tsx index a6618f3fe319c7..1bdf525f066e9b 100644 --- a/apps/web/app/future/auth/forgot-password/[id]/page.tsx +++ b/apps/web/app/future/auth/forgot-password/[id]/page.tsx @@ -3,7 +3,7 @@ import { withAppDir } from "app/AppDirSSRHOC"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; -import { getServerSideProps } from "@server/lib/forgotPasswordWithIdGetData"; +import { getServerSideProps } from "@server/lib/forgot-password/[id]/getServerSideProps"; export const generateMetadata = async () => { return await _generateMetadata( diff --git a/apps/web/app/future/auth/forgot-password/page.tsx b/apps/web/app/future/auth/forgot-password/page.tsx index d65693791cb9c2..9eaa7362bdf97f 100644 --- a/apps/web/app/future/auth/forgot-password/page.tsx +++ b/apps/web/app/future/auth/forgot-password/page.tsx @@ -3,7 +3,7 @@ import { withAppDir } from "app/AppDirSSRHOC"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; -import { getServerSideProps } from "@server/lib/forgotPasswordGetData"; +import { getServerSideProps } from "@server/lib/forgot-password/getServerSideProps"; export const generateMetadata = async () => { return await _generateMetadata( diff --git a/apps/web/pages/auth/forgot-password/[id].tsx b/apps/web/pages/auth/forgot-password/[id].tsx index 6d5ea6a664ed24..05a670c771a345 100644 --- a/apps/web/pages/auth/forgot-password/[id].tsx +++ b/apps/web/pages/auth/forgot-password/[id].tsx @@ -8,7 +8,7 @@ import { Button, PasswordField, Form } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; -import { getServerSideProps } from "@server/lib/forgotPasswordWithIdGetData"; +import { getServerSideProps } from "@server/lib/forgot-password/[id]/getServerSideProps"; type Props = { requestId: string; diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index 031bbe31c76282..decd4508a97a83 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -10,7 +10,7 @@ import { Button, EmailField } from "@calcom/ui"; import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; -import { getServerSideProps } from "@server/lib/forgotPasswordGetData"; +import { getServerSideProps } from "@server/lib/forgot-password/getServerSideProps"; export default function ForgotPassword({ csrfToken }: { csrfToken: string | undefined }) { const { t } = useLocale(); diff --git a/apps/web/server/lib/forgotPasswordWithIdGetData.tsx b/apps/web/server/lib/forgot-password/[id]/getServerSideProps.tsx similarity index 100% rename from apps/web/server/lib/forgotPasswordWithIdGetData.tsx rename to apps/web/server/lib/forgot-password/[id]/getServerSideProps.tsx diff --git a/apps/web/server/lib/forgotPasswordGetData.tsx b/apps/web/server/lib/forgot-password/getServerSideProps.tsx similarity index 100% rename from apps/web/server/lib/forgotPasswordGetData.tsx rename to apps/web/server/lib/forgot-password/getServerSideProps.tsx From 3a105653b9b9e363568ba861f298ad5573219dc0 Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Thu, 11 Jan 2024 19:14:06 +0100 Subject: [PATCH 5/8] use client --- apps/web/pages/auth/forgot-password/[id].tsx | 2 ++ apps/web/pages/auth/forgot-password/index.tsx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/apps/web/pages/auth/forgot-password/[id].tsx b/apps/web/pages/auth/forgot-password/[id].tsx index 05a670c771a345..cbc7e4ad292235 100644 --- a/apps/web/pages/auth/forgot-password/[id].tsx +++ b/apps/web/pages/auth/forgot-password/[id].tsx @@ -1,3 +1,5 @@ +"use client"; + import Link from "next/link"; import type { CSSProperties } from "react"; import { useForm } from "react-hook-form"; diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index decd4508a97a83..3ec6c41d254335 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -1,3 +1,5 @@ +"use client"; + // eslint-disable-next-line no-restricted-imports import { debounce } from "lodash"; import Link from "next/link"; From 7fe720ac64078b1db830c7b44f47f962af21d2a0 Mon Sep 17 00:00:00 2001 From: Sasha Mysak Date: Mon, 15 Jan 2024 16:28:27 +0100 Subject: [PATCH 6/8] fix: rebase on 13.5 --- apps/web/app/future/auth/forgot-password/[id]/page.tsx | 4 ++-- apps/web/app/future/auth/forgot-password/page.tsx | 4 ++-- apps/web/pages/d/[link]/[slug].tsx | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/web/app/future/auth/forgot-password/[id]/page.tsx b/apps/web/app/future/auth/forgot-password/[id]/page.tsx index 1bdf525f066e9b..126faa3a7c236f 100644 --- a/apps/web/app/future/auth/forgot-password/[id]/page.tsx +++ b/apps/web/app/future/auth/forgot-password/[id]/page.tsx @@ -1,5 +1,5 @@ import SetNewUserPassword from "@pages/auth/forgot-password/[id]"; -import { withAppDir } from "app/AppDirSSRHOC"; +import { withAppDirSsr } from "app/WithAppDirSsr"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; @@ -15,5 +15,5 @@ export const generateMetadata = async () => { export default WithLayout({ getLayout: null, Page: SetNewUserPassword, - getData: withAppDir(getServerSideProps), + getData: withAppDirSsr(getServerSideProps), })<"P">; diff --git a/apps/web/app/future/auth/forgot-password/page.tsx b/apps/web/app/future/auth/forgot-password/page.tsx index 9eaa7362bdf97f..5b3bc2787195ed 100644 --- a/apps/web/app/future/auth/forgot-password/page.tsx +++ b/apps/web/app/future/auth/forgot-password/page.tsx @@ -1,5 +1,5 @@ import ForgotPassword from "@pages/auth/forgot-password"; -import { withAppDir } from "app/AppDirSSRHOC"; +import { withAppDirSsr } from "app/WithAppDirSsr"; import { _generateMetadata } from "app/_utils"; import { WithLayout } from "app/layoutHOC"; @@ -15,5 +15,5 @@ export const generateMetadata = async () => { export default WithLayout({ getLayout: null, Page: ForgotPassword, - getData: withAppDir(getServerSideProps), + getData: withAppDirSsr(getServerSideProps), })<"P">; diff --git a/apps/web/pages/d/[link]/[slug].tsx b/apps/web/pages/d/[link]/[slug].tsx index 709527beb24ca9..8a52eff77d3a0d 100644 --- a/apps/web/pages/d/[link]/[slug].tsx +++ b/apps/web/pages/d/[link]/[slug].tsx @@ -1,3 +1,4 @@ +"use client"; import { Booker } from "@calcom/atoms"; import { getBookerWrapperClasses } from "@calcom/features/bookings/Booker/utils/getBookerWrapperClasses"; From 251e2b3460af85b8ef124963834076d913014c13 Mon Sep 17 00:00:00 2001 From: Benny Joo Date: Fri, 19 Jan 2024 18:54:32 +0000 Subject: [PATCH 7/8] fix --- apps/web/pages/auth/forgot-password/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index 3ec6c41d254335..8c473d404bf2d0 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -9,12 +9,15 @@ import React from "react"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Button, EmailField } from "@calcom/ui"; +import { type inferSSRProps } from "@lib/types/inferSSRProps"; + import PageWrapper from "@components/PageWrapper"; import AuthContainer from "@components/ui/AuthContainer"; import { getServerSideProps } from "@server/lib/forgot-password/getServerSideProps"; -export default function ForgotPassword({ csrfToken }: { csrfToken: string | undefined }) { +export default function ForgotPassword(props: inferSSRProps) { + const csrfToken = "csrfToken" in props ? (props.csrfToken as string) : undefined; const { t } = useLocale(); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState<{ message: string } | null>(null); From 5587a1f2c124f544e1f3f227fdb79b397bb6d7a5 Mon Sep 17 00:00:00 2001 From: zomars Date: Fri, 19 Jan 2024 13:50:17 -0700 Subject: [PATCH 8/8] Update forgot-password.e2e.ts --- .../playwright/auth/forgot-password.e2e.ts | 165 +++++++++--------- 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/apps/web/playwright/auth/forgot-password.e2e.ts b/apps/web/playwright/auth/forgot-password.e2e.ts index ad4d30aa3a789d..79bf74ccfafcfe 100644 --- a/apps/web/playwright/auth/forgot-password.e2e.ts +++ b/apps/web/playwright/auth/forgot-password.e2e.ts @@ -5,89 +5,92 @@ import { verifyPassword } from "@calcom/features/auth/lib/verifyPassword"; import prisma from "@calcom/prisma"; import { test } from "../lib/fixtures"; +import { testBothFutureAndLegacyRoutes } from "../lib/future-legacy-routes"; test.afterEach(({ users }) => users.deleteAll()); -test("Can reset forgotten password", async ({ page, users }) => { - const user = await users.create(); - - // Got to reset password flow - await page.goto("/auth/forgot-password"); - - await page.fill('input[name="email"]', `${user.username}@example.com`); - await page.press('input[name="email"]', "Enter"); - - // wait for confirm page. - await page.waitForSelector("text=Reset link sent"); - - // As a workaround, we query the db for the last created password request - // there should be one, otherwise we throw - const { id } = await prisma.resetPasswordRequest.findFirstOrThrow({ - where: { - email: user.email, - }, - select: { - id: true, - }, - orderBy: { - createdAt: "desc", - }, +testBothFutureAndLegacyRoutes.describe("Forgot password", async () => { + test("Can reset forgotten password", async ({ page, users }) => { + const user = await users.create(); + + // Got to reset password flow + await page.goto("/auth/forgot-password"); + + await page.fill('input[name="email"]', `${user.username}@example.com`); + await page.press('input[name="email"]', "Enter"); + + // wait for confirm page. + await page.waitForSelector("text=Reset link sent"); + + // As a workaround, we query the db for the last created password request + // there should be one, otherwise we throw + const { id } = await prisma.resetPasswordRequest.findFirstOrThrow({ + where: { + email: user.email, + }, + select: { + id: true, + }, + orderBy: { + createdAt: "desc", + }, + }); + + // Test when a user changes his email after starting the password reset flow + await prisma.user.update({ + where: { + email: user.email, + }, + data: { + email: `${user.username}-2@example.com`, + }, + }); + + await page.goto(`/auth/forgot-password/${id}`); + + await page.waitForSelector("text=That request is expired."); + + // Change the email back to continue testing. + await prisma.user.update({ + where: { + email: `${user.username}-2@example.com`, + }, + data: { + email: user.email, + }, + }); + + await page.goto(`/auth/forgot-password/${id}`); + + const newPassword = `${user.username}-123CAL-${uuid().toString()}`; // To match the password policy + + // Wait for page to fully load + await page.waitForSelector("text=Reset Password"); + + await page.fill('input[name="new_password"]', newPassword); + await page.click('button[type="submit"]'); + + await page.waitForSelector("text=Password updated"); + + await expect(page.locator(`text=Password updated`)).toBeVisible(); + // now we check our DB to confirm the password was indeed updated. + // we're not logging in to the UI to speed up test performance. + const updatedUser = await prisma.user.findUniqueOrThrow({ + where: { + email: user.email, + }, + select: { + id: true, + password: true, + }, + }); + + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + expect(await verifyPassword(newPassword, updatedUser.password!)).toBeTruthy(); + + // finally, make sure the same URL cannot be used to reset the password again, as it should be expired. + await page.goto(`/auth/forgot-password/${id}`); + + await expect(page.locator(`text=Whoops`)).toBeVisible(); }); - - // Test when a user changes his email after starting the password reset flow - await prisma.user.update({ - where: { - email: user.email, - }, - data: { - email: `${user.username}-2@example.com`, - }, - }); - - await page.goto(`/auth/forgot-password/${id}`); - - await page.waitForSelector("text=That request is expired."); - - // Change the email back to continue testing. - await prisma.user.update({ - where: { - email: `${user.username}-2@example.com`, - }, - data: { - email: user.email, - }, - }); - - await page.goto(`/auth/forgot-password/${id}`); - - const newPassword = `${user.username}-123CAL-${uuid().toString()}`; // To match the password policy - - // Wait for page to fully load - await page.waitForSelector("text=Reset Password"); - - await page.fill('input[name="new_password"]', newPassword); - await page.click('button[type="submit"]'); - - await page.waitForSelector("text=Password updated"); - - await expect(page.locator(`text=Password updated`)).toBeVisible(); - // now we check our DB to confirm the password was indeed updated. - // we're not logging in to the UI to speed up test performance. - const updatedUser = await prisma.user.findUniqueOrThrow({ - where: { - email: user.email, - }, - select: { - id: true, - password: true, - }, - }); - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(await verifyPassword(newPassword, updatedUser.password!)).toBeTruthy(); - - // finally, make sure the same URL cannot be used to reset the password again, as it should be expired. - await page.goto(`/auth/forgot-password/${id}`); - - await expect(page.locator(`text=Whoops`)).toBeVisible(); });