Mintplex-Labs/anything-llm · error · Error

Could not refresh user.

Error message

Could not refresh user.

What it means

Thrown by System.refreshUser on a non-2xx GET to /api/system/refresh-user. It re-fetches the current session's user object. baseHeaders() supplies the Bearer token. The .catch() returns {success:false, user:null, message:e.message}, so a failed refresh effectively logs the user out from the UI's perspective.

Source

Thrown at frontend/src/models/system.js:160

      .then((res) => {
        if (!res.ok) throw new Error("Could not validate login.");
        return res.json();
      })
      .then((res) => res)
      .catch((e) => {
        return { valid: false, message: e.message };
      });
  },
  /**
   * Refreshes the user object from the session.
   * @returns {Promise<{success: boolean, user: Object | null, message: string | null}>}
   */
  refreshUser: () => {
    return fetch(`${API_BASE}/system/refresh-user`, {
      headers: baseHeaders(),
    })
      .then((res) => {
        if (!res.ok) throw new Error("Could not refresh user.");
        return res.json();
      })
      .catch((e) => {
        return { success: false, user: null, message: e.message };
      });
  },
  recoverAccount: async function (username, recoveryCodes) {
    return await fetch(`${API_BASE}/system/recover-account`, {
      method: "POST",
      headers: baseHeaders(),
      body: JSON.stringify({ username, recoveryCodes }),
    })
      .then(async (res) => {
        const data = await res.json();
        if (!res.ok) {
          throw new Error(data.message || "Error recovering account.");
        }
        return data;

View on GitHub (pinned to 526360e320)

Solutions

  1. Trigger a re-login flow when success===false and message indicates auth failure.
  2. Confirm localStorage AUTH_TOKEN is still present and not corrupted.
  3. Check server session/token configuration and TTL.
  4. Verify the /system/refresh-user route is registered in the current backend version (it was added after early versions).

Example fix

// before
const { user } = await System.refreshUser();

// after (handle forced logout)
const res = await System.refreshUser();
if (!res.success) {
  await handleLogout();
  navigate("/login");
  return;
}
setUser(res.user);
Defensive patterns

Strategy: validation

Validate before calling

function hasFreshToken() {
  return !!window.localStorage.getItem("anythingllm_authToken");
}
// if (!hasFreshToken()) skip refreshUser and route to login.

Type guard

/** @param {any} r @returns {r is {success:boolean, user:Object|null}} */
function isRefreshResult(r) {
  return r != null && typeof r.success === "boolean" && (r.user === null || typeof r.user === "object");
}

Try / catch

const res = await System.refreshUser();
if (!isRefreshResult(res) || !res.success) {
  await handleLogout();
  navigate("/login");
}

Prevention

When it happens

Trigger: Calling refreshUser() when the Bearer token in localStorage has expired (401/403), when the session was invalidated server-side, or when the user record was deleted between token issue and refresh.

Common situations: Token TTL elapsed mid-session; an admin revoked the user; the database user table was modified externally; clock skew between client and server rejects the token.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/e047b12da9503edf. Report an issue: GitHub.