You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Portfolio/src/utils/session.ts

30 lines
738 B

import { withIronSessionApiRoute, withIronSessionSsr } from "iron-session/next";
import {
GetServerSidePropsContext,
GetServerSidePropsResult,
NextApiHandler
} from "next";
import { sessionOptions } from "./config";
import { User } from "@prisma/client";
export const withIronSession = (handler: NextApiHandler) =>
withIronSessionApiRoute(handler, sessionOptions);
export function withSessionSsr<
P extends { [key: string]: unknown } = { [key: string]: unknown }
>(
handler: (
context: GetServerSidePropsContext
) => GetServerSidePropsResult<P> | Promise<GetServerSidePropsResult<P>>
) {
return withIronSessionSsr(handler, sessionOptions);
}
declare module "iron-session" {
interface IronSessionData {
user?: User;
}
}