import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'; import { ParsedUrlQuery } from 'querystring'; import { IncomingSSR } from '../../model/common'; import getSSRUser from './getSSRUser'; const withUserSSR = < // eslint-disable-next-line @typescript-eslint/no-explicit-any P extends { [key: string]: any } = { [key: string]: any }, Q extends ParsedUrlQuery = ParsedUrlQuery, >( incomingGSSP?: IncomingSSR, ) => { return async ( ctx: GetServerSidePropsContext, ): Promise> => { const user = await getSSRUser(ctx.req.cookies); if (!user) { return { redirect: { destination: '/login', statusCode: 301, }, }; } const result = await incomingGSSP(ctx, user); return result; }; }; export default withUserSSR;