mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
Update JWT_SECRET handling
This commit is contained in:
@@ -32,6 +32,7 @@ const PROTECTED_API_PATHS = [
|
||||
"/api/provider-nodes/validate",
|
||||
"/api/cli-tools",
|
||||
"/api/mcp",
|
||||
"/api/translator",
|
||||
];
|
||||
|
||||
// Routes that spawn child processes — restrict to localhost regardless of auth.
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
import { SignJWT, jwtVerify } from "jose";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import crypto from "node:crypto";
|
||||
import { DATA_DIR } from "@/lib/dataDir";
|
||||
|
||||
const SECRET = new TextEncoder().encode(
|
||||
process.env.JWT_SECRET || "9router-default-secret-change-me"
|
||||
);
|
||||
function loadJwtSecret() {
|
||||
if (process.env.JWT_SECRET) return process.env.JWT_SECRET;
|
||||
const file = path.join(DATA_DIR, "jwt-secret");
|
||||
try {
|
||||
return fs.readFileSync(file, "utf8").trim();
|
||||
} catch {}
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
const generated = crypto.randomBytes(32).toString("hex");
|
||||
fs.writeFileSync(file, generated, { mode: 0o600 });
|
||||
return generated;
|
||||
}
|
||||
|
||||
const SECRET = new TextEncoder().encode(loadJwtSecret());
|
||||
|
||||
export function shouldUseSecureCookie(request) {
|
||||
const forceSecureCookie = process.env.AUTH_COOKIE_SECURE === "true";
|
||||
|
||||
@@ -12,5 +12,6 @@ export const config = {
|
||||
"/api/provider-nodes/validate",
|
||||
"/api/cli-tools/:path*",
|
||||
"/api/mcp/:path*",
|
||||
"/api/translator/:path*",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user