{"record":{"id":"ea054a3ac2d52a0f","repo":"QuantumNous/new-api","slug":"verification-scope-is-missing","errorCode":null,"errorMessage":"Verification scope is missing","messagePattern":"Verification scope is missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/src/features/auth/secure-verification/hooks/use-secure-verification.ts","lineNumber":152,"sourceCode":"\n  const executeVerification = useCallback(\n    async (method?: VerificationMethod, code?: string) => {\n      if (!state.apiCall) {\n        toast.error(i18next.t('Verification is not configured properly'))\n        return\n      }\n\n      const actualMethod = method ?? state.method\n      if (!actualMethod) {\n        toast.error(i18next.t('Select a verification method first'))\n        return\n      }\n\n      setState((prev) => ({ ...prev, loading: true }))\n\n      try {\n        if (!state.scope) {\n          throw new Error(i18next.t('Verification scope is missing'))\n        }\n        const proof = await verify(\n          actualMethod,\n          state.scope,\n          code ?? state.code\n        )\n        const result = await state.apiCall(proof.proof_token)\n\n        if (successMessage) {\n          toast.success(successMessage)\n        }\n\n        onSuccess?.(result, actualMethod)\n\n        if (autoReset) {\n          reset()\n        }\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/features/auth/secure-verification/hooks/use-secure-verification.ts#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that every usage opens the verification flow with a scope before submit can fire (disable confirm until scope is set).","Guard the confirm button on !!state.scope so the error can never reach the user.","Audit the hook lifecycle: ensure reset() cannot race a pending submit.","If a remount drops scope, lift scope into a ref or the parent so it survives re-renders."],"exampleFix":"// before\n<button onClick={handleSubmit}>Confirm</button>\n\n// after\n<button disabled={!state.scope} onClick={handleSubmit}>Confirm</button>","handlingStrategy":"validation","validationCode":"if (!scope) {\n  toast.error('Verification session is not ready. Please reopen the dialog.')\n  return\n}","typeGuard":"const isSecurityProofScope = (s: unknown): s is SecurityProofScope =>\n  typeof s === 'string' && s.length > 0","tryCatchPattern":null,"preventionTips":["Disable the confirm button until the hook has both method and scope set","Open the verification dialog with an explicit scope before any submit is possible","Keep scope in a ref or parent state so component remounts cannot drop it mid-flow"],"tags":["verification","react-state","lifecycle","frontend"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}