mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-11-18 03:26:17 +00:00
Update settings.tsx
This commit is contained in:
@@ -318,6 +318,8 @@ export function Settings() {
|
|||||||
setGeneratingToken(true)
|
setGeneratingToken(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log("[v0] Generating API token with password and 2FA:", { totpEnabled, hasTotpCode: !!tokenTotpCode })
|
||||||
|
|
||||||
const response = await fetchApi("/api/auth/generate-api-token", {
|
const response = await fetchApi("/api/auth/generate-api-token", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@@ -327,19 +329,24 @@ export function Settings() {
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Parse response first
|
console.log("[v0] Response status:", response.status, response.statusText)
|
||||||
let data
|
|
||||||
try {
|
const data = await response.json()
|
||||||
data = await response.json()
|
console.log("[v0] Parsed response data:", { success: data.success, hasToken: !!data.token })
|
||||||
} catch (parseError) {
|
|
||||||
throw new Error("Invalid server response")
|
if (!response.ok) {
|
||||||
|
throw new Error(data.message || data.error || "Failed to generate API token")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then check if request was successful
|
if (!data.success) {
|
||||||
if (!response.ok || !data.success) {
|
|
||||||
throw new Error(data.message || "Failed to generate API token")
|
throw new Error(data.message || "Failed to generate API token")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!data.token) {
|
||||||
|
throw new Error("No token received from server")
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("[v0] API token generated successfully")
|
||||||
setApiToken(data.token)
|
setApiToken(data.token)
|
||||||
setSuccess("API token generated successfully! Make sure to copy it now as you won't be able to see it again.")
|
setSuccess("API token generated successfully! Make sure to copy it now as you won't be able to see it again.")
|
||||||
setTokenPassword("")
|
setTokenPassword("")
|
||||||
|
|||||||
Reference in New Issue
Block a user