QuantumNous/new-api · error · Error

Failed to load login sessions

Error message

Failed to load login sessions

What it means

Thrown inside the react-query queryFn of the login-sessions card when getLoginSessions() resolves with success=false. The thrown message becomes the query error rendered by the card; on success it defaults to an empty session list.

Source

Thrown at web/src/features/profile/components/login-sessions-card.tsx:70

} from '../api'
import { LoginSessionDialogs } from './login-session-dialogs'
import { LoginSessionItem } from './login-session-item'

const sessionQueryKey = ['profile', 'login-sessions'] as const

export function LoginSessionsCard() {
  const { t } = useTranslation()
  const navigate = useNavigate()
  const queryClient = useQueryClient()
  const [revokeTarget, setRevokeTarget] = useState<LoginSession | null>(null)
  const [confirmOthers, setConfirmOthers] = useState(false)

  const sessionsQuery = useQuery({
    queryKey: sessionQueryKey,
    queryFn: async () => {
      const response = await getLoginSessions()
      if (!response.success) {
        throw new Error(response.message || t('Failed to load login sessions'))
      }
      return response.data ?? []
    },
  })

  const revokeMutation = useMutation({
    mutationFn: async (sid: string) => {
      const response = await revokeLoginSession(sid)
      if (!response.success) {
        throw new Error(response.message || t('Failed to sign out session'))
      }
      return sid
    },
    onSuccess: async (sid) => {
      const revokedCurrent = sessionsQuery.data?.some(
        (session) => session.sid === sid && session.current
      )
      setRevokeTarget(null)

View on GitHub (pinned to e2c7aa7b10)

Solutions

  1. Refresh the page / re-login — expired-token 401 is the most common cause
  2. Confirm the login-session feature is enabled in admin system settings
  3. Check backend health of the session store (Redis) if the endpoint 500s
  4. Call getLoginSessions' endpoint directly and read the message field for the precise reason

Example fix

// before
const response = await getLoginSessions()
if (!response.success) {
  throw new Error(response.message || t('Failed to load login sessions'))
}
return response.data ?? []
// after - treat 401 explicitly so the app can route to login
const response = await getLoginSessions()
if (!response.success) {
  if (isAuthError(response)) {
    navigate('/login', { state: { from: location.pathname } })
    return []
  }
  throw new Error(response.message || t('Failed to load login sessions'))
}
return response.data ?? []
Defensive patterns

Strategy: try-catch

Validate before calling

// no client preconditions beyond auth; ensure the query is gated on an authenticated session
enabled: isAuthenticated

Try / catch

// inside queryFn
const response = await getLoginSessions()
if (!response.success) {
  throw new Error(response.message || t('Failed to load login sessions'))
}
return response.data ?? []
// card renders query.error?.message when present

Prevention

When it happens

Trigger: Opening the profile page's login sessions card while the sessions endpoint fails: 401 from an expired session, 403 when the feature is disabled by policy, or a backend error listing sessions from the token/session store.

Common situations: Current session expired so every profile query 401s; session-management feature disabled in system settings; Redis/session store down on the backend; backend version without the sessions route.

Related errors


AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15). Data as JSON: /api/errors/eca22a5728f8f799. Report an issue: GitHub.