d13100ebf3
Update draft releases / main (push) Has been cancelled
Build and push docs image / build-image (push) Has been cancelled
Build Web Application / build-web (macos-latest) (push) Has been cancelled
Build Web Application / build-web (ubuntu-latest) (push) Has been cancelled
Python Code Quality Checks / build (push) Has been cancelled
Test Python / test-python (macos-latest, 3.10) (push) Has been cancelled
Test Python / test-python (macos-latest, 3.11) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.10) (push) Has been cancelled
Test Python / test-python (ubuntu-latest, 3.11) (push) Has been cancelled
30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import type { IronSessionOptions } from 'iron-session';
|
|
import { withIronSessionApiRoute, withIronSessionSsr } from 'iron-session/next';
|
|
import { GetServerSidePropsContext, GetServerSidePropsResult, NextApiHandler } from 'next';
|
|
import { UserModel } from './dto/models/user.dto';
|
|
|
|
export const sessionOptions: IronSessionOptions = {
|
|
password: process.env.SECRET_COOKIE_PASSWORD as string,
|
|
cookieName: 'dbgpt-portal',
|
|
cookieOptions: {
|
|
secure: process.env.NODE_ENV === 'production',
|
|
},
|
|
};
|
|
|
|
export function withSessionRoute(handler: NextApiHandler) {
|
|
return withIronSessionApiRoute(handler, sessionOptions);
|
|
}
|
|
|
|
// 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, sessionOptions);
|
|
}
|
|
|
|
declare module 'iron-session' {
|
|
interface IronSessionData {
|
|
user: UserModel;
|
|
}
|
|
}
|