fix: align login and home routing with leaudit backend
This commit is contained in:
+6
-16
@@ -103,10 +103,11 @@ export async function action({ request }: ActionFunctionArgs) {
|
||||
const response = await loginWithPassword(username.trim(), password.trim());
|
||||
|
||||
if (!response.success || !response.data) {
|
||||
console.error("❌ [Login Action] 登录失败:", response.error);
|
||||
const loginError = response.error || response.message || "登录失败,请检查用户名和密码";
|
||||
console.error("❌ [Login Action] 登录失败:", loginError);
|
||||
return Response.json({
|
||||
success: false,
|
||||
error: response.error || "登录失败,请检查用户名和密码"
|
||||
error: loginError
|
||||
}, { status: 401 });
|
||||
}
|
||||
|
||||
@@ -133,25 +134,14 @@ export async function action({ request }: ActionFunctionArgs) {
|
||||
// if(!user_info.area){
|
||||
// user_info.area = '梅州'
|
||||
// }
|
||||
|
||||
// 🔑 将后端返回的 issued_time 转换为时间戳(毫秒)
|
||||
let tokenIssuedAt = Date.now(); // 默认使用当前时间
|
||||
if (issued_time) {
|
||||
try {
|
||||
// 后端返回格式:"2025-11-18 17:41:06"
|
||||
// 转换为时间戳(毫秒)
|
||||
tokenIssuedAt = new Date(issued_time.replace(' ', 'T')).getTime();
|
||||
console.log("📅 [Login Action] 使用后端返回的签发时间:", issued_time, "→", tokenIssuedAt);
|
||||
} catch (error) {
|
||||
console.warn("⚠️ [Login Action] 无法解析 issued_time,使用当前时间:", error);
|
||||
}
|
||||
}
|
||||
// 直接使用当前服务端时间作为 session 签发时间,避免后端返回的本地时间字符串被 Node 以不同时区解析
|
||||
const tokenIssuedAt = Date.now();
|
||||
|
||||
console.log("✅ [Login Action] 登录成功,准备创建 session");
|
||||
// console.log("📦 [Login Action] 后端返回完整数据:", response.data);
|
||||
console.log("👤 [Login Action] 用户角色:", user_info.user_role); // 应该是 "admin"
|
||||
console.log("⏰ [Login Action] Token 有效期:", expires_in, "秒 (", expires_in / 3600, "小时)");
|
||||
|
||||
|
||||
// ✅ 账密登录直接写入 Cookie Session 并跳首页
|
||||
// localStorage 由 root 中的客户端会话引导逻辑补写,避免 callback 跳转链路卡住
|
||||
return createUserSession({
|
||||
|
||||
Reference in New Issue
Block a user