Files
calendar/apps/web/server/lib/auth/forgot-password/getServerSideProps.tsx
T
Benny JooandGitHub d059b1399b chore: App router migration - /auth/forgot-password/*, /auth/login, /auth/logout (#16467)
* migrate auth/forgot-password/*, auth/login, auth/logout

* revert

* fix forgot password

* fix folder structure

* fix logout

* fix middleware

* remove TODO log

* refactor logout
2024-09-03 18:53:16 +09:00

47 lines
1.3 KiB
TypeScript

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 getServerSideProps(context: GetServerSidePropsContext) {
const { req, res } = context;
const session = await getServerSession({ req });
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 async function getServerSidePropsAppDir(context: GetServerSidePropsContext) {
const { req } = context;
const session = await getServerSession({ req });
if (session) {
const redirect = await import("next/navigation").then((mod) => mod.redirect);
redirect("/");
return { props: {} };
}
const locale = await getLocale(context.req);
return {
props: {
csrfToken: await getCsrfToken(context),
...(await serverSideTranslations(locale, ["common"])),
},
};
}