From 3b832fe605339844a8c5a9d789571819360337f2 Mon Sep 17 00:00:00 2001 From: Nezumi-2711 Date: Wed, 15 Jul 2026 10:50:35 +0700 Subject: [PATCH] fix: update the logic for change password --- src/app/(dashboard)/dashboard/profile/page.js | 24 ++-------------- .../usage/components/ProviderLimits/index.js | 28 ------------------- .../usage/components/RequestDetailsTab.js | 4 +-- src/app/api/settings/route.js | 10 ++----- src/lib/db/repos/usageRepo.js | 1 - src/shared/components/RequestLogger.js | 2 +- src/shared/components/UsageStats.js | 6 ++-- 7 files changed, 10 insertions(+), 65 deletions(-) diff --git a/src/app/(dashboard)/dashboard/profile/page.js b/src/app/(dashboard)/dashboard/profile/page.js index 02524a35..6f4dcb3f 100644 --- a/src/app/(dashboard)/dashboard/profile/page.js +++ b/src/app/(dashboard)/dashboard/profile/page.js @@ -31,7 +31,7 @@ export default function ProfilePage() { const [langOpen, setLangOpen] = useState(false); const [settings, setSettings] = useState({ fallbackStrategy: "fill-first" }); const [loading, setLoading] = useState(true); - const [passwords, setPasswords] = useState({ current: "", new: "", confirm: "" }); + const [passwords, setPasswords] = useState({ new: "", confirm: "" }); const [passStatus, setPassStatus] = useState({ type: "", message: "" }); const [passLoading, setPassLoading] = useState(false); const [dbLoading, setDbLoading] = useState(false); @@ -138,7 +138,6 @@ export default function ProfilePage() { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ - currentPassword: passwords.current, newPassword: passwords.new, }), }); @@ -147,7 +146,7 @@ export default function ProfilePage() { if (res.ok) { setPassStatus({ type: "success", message: "Password updated successfully" }); - setPasswords({ current: "", new: "", confirm: "" }); + setPasswords({ new: "", confirm: "" }); } else { setPassStatus({ type: "error", message: data.error || "Failed to update password" }); } @@ -421,25 +420,6 @@ export default function ProfilePage() {

Password

- {settings.hasPassword && ( -
- - setPasswords({ ...passwords, current: e.target.value })} - required - /> -
- )} - {/* {!settings.hasPassword && ( -
-

- Setting password for the first time. Leave current password empty or use default: 123456 -

-
- )} */}
diff --git a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js index ee0a03cb..b75028c9 100644 --- a/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js +++ b/src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js @@ -131,7 +131,6 @@ export default function ProviderLimits() { const [lastUpdated, setLastUpdated] = useState(null); const [hasHydratedAutoRefresh, setHasHydratedAutoRefresh] = useState(false); const [refreshingAll, setRefreshingAll] = useState(false); - const [countdown, setCountdown] = useState(60); const [connectionsLoading, setConnectionsLoading] = useState(true); const [deletingId, setDeletingId] = useState(null); const [togglingId, setTogglingId] = useState(null); @@ -165,7 +164,6 @@ export default function ProviderLimits() { }); const intervalRef = useRef(null); - const countdownRef = useRef(null); const tickCountRef = useRef(0); const fetchConnections = useCallback( @@ -461,7 +459,6 @@ export default function ProviderLimits() { if (refreshingAll) return; setRefreshingAll(true); - setCountdown(60); // Throttle Claude: poll its quota every Nth auto-tick (manual force bypasses) const tick = (tickCountRef.current += 1); @@ -571,10 +568,6 @@ export default function ProviderLimits() { clearInterval(intervalRef.current); intervalRef.current = null; } - if (countdownRef.current) { - clearInterval(countdownRef.current); - countdownRef.current = null; - } return; } @@ -583,17 +576,8 @@ export default function ProviderLimits() { refreshAll(); }, REFRESH_INTERVAL_MS); - // Countdown interval - countdownRef.current = setInterval(() => { - setCountdown((prev) => { - if (prev <= 1) return 60; - return prev - 1; - }); - }, 1000); - return () => { if (intervalRef.current) clearInterval(intervalRef.current); - if (countdownRef.current) clearInterval(countdownRef.current); }; }, [autoRefresh, refreshAll, hasHydratedAutoRefresh]); @@ -605,16 +589,9 @@ export default function ProviderLimits() { clearInterval(intervalRef.current); intervalRef.current = null; } - if (countdownRef.current) { - clearInterval(countdownRef.current); - countdownRef.current = null; - } } else if (autoRefresh && hasHydratedAutoRefresh) { // Resume auto-refresh when tab becomes visible intervalRef.current = setInterval(() => refreshAll(), REFRESH_INTERVAL_MS); - countdownRef.current = setInterval(() => { - setCountdown((prev) => (prev <= 1 ? 60 : prev - 1)); - }, 1000); } }; @@ -927,11 +904,6 @@ export default function ProviderLimits() { Auto-refresh - {autoRefresh && ( - - ({countdown}s) - - )} diff --git a/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js b/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js index 87bf05ab..f65d3bb3 100644 --- a/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js +++ b/src/app/(dashboard)/dashboard/usage/components/RequestDetailsTab.js @@ -287,7 +287,7 @@ export default function RequestDetailsTab() { className="border-b border-black/5 dark:border-white/5 last:border-b-0 hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors" > - {formatVietnamDateTime(detail.timestamp, { dateStyle: "medium", timeStyle: "medium" }) || "—"} + {formatVietnamDateTime(detail.timestamp, { dateStyle: "medium", timeStyle: "short" }) || "—"} {detail.model} @@ -359,7 +359,7 @@ export default function RequestDetailsTab() {
Timestamp:{" "} - {formatVietnamDateTime(selectedDetail.timestamp, { dateStyle: "medium", timeStyle: "medium" }) || "—"} + {formatVietnamDateTime(selectedDetail.timestamp, { dateStyle: "medium", timeStyle: "short" }) || "—"}
Provider:{" "} diff --git a/src/app/api/settings/route.js b/src/app/api/settings/route.js index 0c07bd83..ee92c05b 100644 --- a/src/app/api/settings/route.js +++ b/src/app/api/settings/route.js @@ -4,7 +4,7 @@ import { applyOutboundProxyEnv } from "@/lib/network/outboundProxy"; import { resetComboRotation } from "open-sse/services/combo.js"; import { runQuotaAutoPingTick } from "@/shared/services/quotaAutoPing"; import { requireCurrentDashboardUser, requireUsageDashboardUser } from "@/lib/auth/currentUser"; -import { updateUser, verifyUserPassword } from "@/lib/db"; +import { updateUser } from "@/lib/db"; export const dynamic = "force-dynamic"; export const revalidate = 0; @@ -115,7 +115,7 @@ export async function PATCH(request) { // Strip protected secrets before any internal handling sets them for (const key of PROTECTED_SETTING_KEYS) delete body[key]; - // If updating password, hash it + // An authenticated dashboard session is sufficient to change its own password. if (body.newPassword) { let user; try { @@ -124,12 +124,6 @@ export async function PATCH(request) { return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } - if (!body.currentPassword) { - return NextResponse.json({ error: "Current password required" }, { status: 400 }); - } - if (!(await verifyUserPassword(user.id, body.currentPassword))) { - return NextResponse.json({ error: "Invalid current password" }, { status: 401 }); - } await updateUser(user.id, { password: body.newPassword }); delete body.newPassword; delete body.currentPassword; diff --git a/src/lib/db/repos/usageRepo.js b/src/lib/db/repos/usageRepo.js index fe5bbb51..943857e6 100644 --- a/src/lib/db/repos/usageRepo.js +++ b/src/lib/db/repos/usageRepo.js @@ -1002,7 +1002,6 @@ function formatLogDate(date = new Date()) { year: "numeric", hour: "2-digit", minute: "2-digit", - second: "2-digit", hourCycle: "h23", }); } diff --git a/src/shared/components/RequestLogger.js b/src/shared/components/RequestLogger.js index f13b518a..686bfbf6 100644 --- a/src/shared/components/RequestLogger.js +++ b/src/shared/components/RequestLogger.js @@ -43,7 +43,7 @@ export default function RequestLogger() {

Request Logs