mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 08:29:25 +08:00
fix: 认证 Cookie 判定函数改名避免 ESLint Hook 规则误判
- 将 secureAuthCookie 从 use 前缀改名,保持同一 HTTPS 判定行为 Refs: https://github.com/margrop/wrong-notebook/issues/176
This commit is contained in:
@@ -6,7 +6,7 @@ import type { AuthenticatedContext } from "@/lib/api-handler";
|
||||
import { validationError } from "@/lib/api-errors";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { ADMIN_VIEW_AS_COOKIE, ADMIN_VIEW_AS_MAX_AGE } from "@/lib/admin-view-as";
|
||||
import { useSecureAuthCookie } from "@/lib/auth-cookie";
|
||||
import { secureAuthCookie } from "@/lib/auth-cookie";
|
||||
|
||||
const bodySchema = z.object({ userId: z.string().min(1) });
|
||||
|
||||
@@ -43,7 +43,7 @@ export const POST = withAdmin(async (req: Request) => {
|
||||
store.set(ADMIN_VIEW_AS_COOKIE, target.id, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: useSecureAuthCookie(req),
|
||||
secure: secureAuthCookie(req),
|
||||
path: "/",
|
||||
maxAge: ADMIN_VIEW_AS_MAX_AGE,
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* 2. NEXTAUTH_URL 显式声明 https 时加 secure;
|
||||
* 3. 路由层能拿到请求时,按请求协议是否为 https 判定。
|
||||
*/
|
||||
export function useSecureAuthCookie(request?: Request): boolean {
|
||||
export function secureAuthCookie(request?: Request): boolean {
|
||||
if (process.env.NODE_ENV !== "production") return false;
|
||||
if (process.env.NEXTAUTH_URL?.startsWith("https")) return true;
|
||||
if (!request) return false;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { createLogger } from "@/lib/logger"
|
||||
import { DEFAULT_ADMIN_PASSWORD, isDefaultAdminPassword } from "@/lib/default-admin"
|
||||
import { TOO_MANY_ATTEMPTS } from "@/lib/auth-errors"
|
||||
import { getClientIp, loginAccountLimiter, loginIpLimiter } from "@/lib/rate-limit"
|
||||
import { useSecureAuthCookie } from "@/lib/auth-cookie"
|
||||
import { secureAuthCookie } from "@/lib/auth-cookie"
|
||||
|
||||
const logger = createLogger('auth');
|
||||
|
||||
@@ -34,7 +34,7 @@ export const authOptions: NextAuthOptions = {
|
||||
path: "/",
|
||||
// Only use secure cookies if explicitly running on HTTPS (via NEXTAUTH_URL)
|
||||
// This enables HTTP local IP access in Docker/Production if NEXTAUTH_URL is unset
|
||||
secure: useSecureAuthCookie(),
|
||||
secure: secureAuthCookie(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user