Files
zuauth/src/utils/withSession.ts
2023-11-01 21:10:21 +00:00

15 lines
756 B
TypeScript

import { ironOptions } from "@/config/iron"
import { withIronSessionApiRoute, withIronSessionSsr } from "iron-session/next"
import { GetServerSidePropsContext, GetServerSidePropsResult, NextApiHandler } from "next"
export function withSessionRoute(handler: NextApiHandler) {
return withIronSessionApiRoute(handler, ironOptions)
}
// Theses types are compatible with InferGetStaticPropsType https://nextjs.org/docs/basic-features/data-fetching#typescript-use-getstaticprops
export function withSessionSsr<P extends { [key: string]: unknown } = { [key: string]: unknown }>(
handler: (context: GetServerSidePropsContext) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>
) {
return withIronSessionSsr(handler, ironOptions)
}