charles_c 5 hónapja
szülő
commit
40b2ca0ef3
2 módosított fájl, 17 hozzáadás és 0 törlés
  1. 2 0
      Dockerfile.prod
  2. 15 0
      src/app/api/auth/login/route.js

+ 2 - 0
Dockerfile.prod

@@ -36,6 +36,8 @@ FROM node:18-alpine AS runner
 WORKDIR /app
 WORKDIR /app
 
 
 ENV NODE_ENV production
 ENV NODE_ENV production
+ENV JWT_SECRET=${JWT_SECRET}
+ENV MONGODB_URI=${MONGODB_URI}
 
 
 # 安装 bash
 # 安装 bash
 RUN apk add --no-cache bash 
 RUN apk add --no-cache bash 

+ 15 - 0
src/app/api/auth/login/route.js

@@ -7,12 +7,27 @@ import jwt from "jsonwebtoken";
 
 
 const JWT_SECRET = process.env.JWT_SECRET;
 const JWT_SECRET = process.env.JWT_SECRET;
 
 
+// 添加调试日志
+console.log("Environment variables:", {
+  hasJwtSecret: !!process.env.JWT_SECRET,
+  jwtSecretValue: process.env.JWT_SECRET,
+  nodeEnv: process.env.NODE_ENV,
+});
+
 export async function POST(request) {
 export async function POST(request) {
   await dbConnect();
   await dbConnect();
 
 
   try {
   try {
     const { username, password } = await request.json();
     const { username, password } = await request.json();
 
 
+    if (!process.env.JWT_SECRET) {
+      console.error("JWT_SECRET is missing");
+      return NextResponse.json(
+        { success: false, error: "Server configuration error" },
+        { status: 500 }
+      );
+    }
+
     let response;
     let response;
 
 
     // 检查所有必要字段是否都已提供
     // 检查所有必要字段是否都已提供