mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-27 13:57:46 +00:00
Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: 谨欣 <echo.cmy@antgroup.com> Co-authored-by: 严志勇 <yanzhiyong@tiansuixiansheng.com> Co-authored-by: yanzhiyong <932374019@qq.com>
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;
|
|
}
|
|
}
|