* Migrate d/* page group * Fix metadata * manual: fix type of arg of getData * fix * manual: fix type errors * Fix type errors * fix type errors * fix error * fix * fix build error
22 lines
736 B
TypeScript
22 lines
736 B
TypeScript
import type { GetServerSideProps, GetServerSidePropsContext } from "next";
|
|
import { notFound, redirect } from "next/navigation";
|
|
|
|
export const withAppDir =
|
|
<T extends Record<string, any>>(getServerSideProps: GetServerSideProps<T>) =>
|
|
async (context: GetServerSidePropsContext): Promise<T> => {
|
|
const ssrResponse = await getServerSideProps(context);
|
|
|
|
if ("redirect" in ssrResponse) {
|
|
redirect(ssrResponse.redirect.destination);
|
|
}
|
|
if ("notFound" in ssrResponse) {
|
|
notFound();
|
|
}
|
|
|
|
return {
|
|
...ssrResponse.props,
|
|
// includes dehydratedState required for future page trpcPropvider
|
|
...("trpcState" in ssrResponse.props && { dehydratedState: ssrResponse.props.trpcState }),
|
|
};
|
|
};
|