rallly/packages/backend/next/utils.ts
Luke Vella c22b3abc4d
⬆️ v3.0.0 (#704)
2023-06-19 17:17:00 +01:00

25 lines
510 B
TypeScript

import { GetServerSideProps } from "next";
export function composeGetServerSideProps(
...fns: GetServerSideProps[]
): GetServerSideProps {
return async (ctx) => {
const res = { props: {} };
for (const getServerSideProps of fns) {
const fnRes = await getServerSideProps(ctx);
if ("redirect" in fnRes) {
return fnRes;
}
if ("props" in fnRes) {
res.props = {
...res.props,
...fnRes.props,
};
}
}
return res;
};
}