refactor: 收口 Admin 会话与授权边界
This commit is contained in:
1 parent
0788480ce3
commit
4ef4be2071
67 files changed
+1890
-392
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import type { FastifyReply } from "fastify";
|
||||
|
||||
export const ADMIN_SESSION_COOKIE = "admin_session";
|
||||
const ADMIN_SESSION_MAX_AGE_SECONDS = 60 * 60 * 24 * 7;
|
||||
|
||||
export function setAdminSessionCookie(reply: FastifyReply, token: string): void {
|
||||
reply.setCookie(ADMIN_SESSION_COOKIE, token, {
|
||||
path: "/",
|
||||
httpOnly: true,
|
||||
sameSite: "strict",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
maxAge: ADMIN_SESSION_MAX_AGE_SECONDS,
|
||||
});
|
||||
}
|
||||
|
||||
export function clearAdminSessionCookie(reply: FastifyReply): void {
|
||||
reply.clearCookie(ADMIN_SESSION_COOKIE, {
|
||||
path: "/",
|
||||
httpOnly: true,
|
||||
sameSite: "strict",
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user