fix: invalid-credentials code, no refresh on wrong pw

This commit is contained in:
2026-10-26 02:58:55 +01:00
parent 4714216093
commit bc3c9e3d23
10 changed files with 44 additions and 8 deletions

View File

@@ -80,6 +80,7 @@ export function DeleteAccountDialog({
<Input
id="delete-password"
type="password"
autoFocus
autoComplete="current-password"
value={password}
onChange={(e) => setPassword(e.target.value)}

View File

@@ -242,7 +242,10 @@ export function useAdminDeleteUser() {
return useMutation({
mutationFn: ({ id, password }: DeleteAccountRequest & { id: string }) =>
delWithBody(`/users/${id}`, { password }),
onSuccess: () => {
onSuccess: (_data, { id }) => {
qc.removeQueries({
predicate: (q) => q.queryKey[0] === userKeys.all[0] && q.queryKey[1] === id,
})
qc.invalidateQueries({ queryKey: userKeys.all })
qc.invalidateQueries({ queryKey: ["activity-feed"] })
},

View File

@@ -68,6 +68,15 @@ async function tryRefresh(): Promise<boolean> {
}
}
async function isInvalidCredentials(res: Response): Promise<boolean> {
try {
const body = await res.clone().json()
return body?.code === "INVALID_CREDENTIALS"
} catch {
return false
}
}
async function request<T = void>(
url: string,
options?: RequestInit,
@@ -81,6 +90,11 @@ async function request<T = void>(
})
if (!res.ok) {
if (res.status === 401) {
// A failed re-auth check (wrong password) is not an expired session:
// no refresh, no retry, no logout.
if (await isInvalidCredentials(res)) {
throw new ApiError(res.status, await res.text())
}
if (url.includes("/auth/refresh") || url.includes("/auth/login")) {
clearAuth()
window.location.href = "/app/login"

View File

@@ -211,7 +211,7 @@
"done": "User deleted",
"errors": {
"wrongPassword": "Wrong password",
"lastAdmin": "You are the last admin and cannot be deleted",
"lastAdmin": "The last admin account cannot be deleted",
"forbidden": "Only admins can delete other users",
"notFound": "User not found",
"generic": "Could not delete account"