QuantumNous/new-api · error · Error

Verification scope is missing

Error message

Verification scope is missing

What it means

Thrown in use-secure-verification's submit handler when state.scope is falsy right before calling verify(). The scope (a SecurityProofScope identifying what operation the proof authorizes) is expected to be seeded into the hook's state when the dialog opens; a missing scope means the hook was misused or its state was reset prematurely.

Source

Thrown at web/src/features/auth/secure-verification/hooks/use-secure-verification.ts:152

  const executeVerification = useCallback(
    async (method?: VerificationMethod, code?: string) => {
      if (!state.apiCall) {
        toast.error(i18next.t('Verification is not configured properly'))
        return
      }

      const actualMethod = method ?? state.method
      if (!actualMethod) {
        toast.error(i18next.t('Select a verification method first'))
        return
      }

      setState((prev) => ({ ...prev, loading: true }))

      try {
        if (!state.scope) {
          throw new Error(i18next.t('Verification scope is missing'))
        }
        const proof = await verify(
          actualMethod,
          state.scope,
          code ?? state.code
        )
        const result = await state.apiCall(proof.proof_token)

        if (successMessage) {
          toast.success(successMessage)
        }

        onSuccess?.(result, actualMethod)

        if (autoReset) {
          reset()
        }

View on GitHub (pinned to e2c7aa7b10)

Solutions

  1. Check that every usage opens the verification flow with a scope before submit can fire (disable confirm until scope is set).
  2. Guard the confirm button on !!state.scope so the error can never reach the user.
  3. Audit the hook lifecycle: ensure reset() cannot race a pending submit.
  4. If a remount drops scope, lift scope into a ref or the parent so it survives re-renders.

Example fix

// before
<button onClick={handleSubmit}>Confirm</button>

// after
<button disabled={!state.scope} onClick={handleSubmit}>Confirm</button>
Defensive patterns

Strategy: validation

Validate before calling

if (!scope) {
  toast.error('Verification session is not ready. Please reopen the dialog.')
  return
}

Type guard

const isSecurityProofScope = (s: unknown): s is SecurityProofScope =>
  typeof s === 'string' && s.length > 0

Prevention

When it happens

Trigger: Calling the hook's submit/confirm handler before open(scope) initialized state; closing and reopening the dialog while a submit was queued; component remount losing state.scope but keeping a stale handler reference; forgetting to pass scope to the hook's initializer.

Common situations: Dialog component remounts (key change) between user typing the code and clicking confirm; hook consumed outside its intended open→verify lifecycle; race where reset() runs on close concurrently with submit.

Related errors


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