{"record":{"id":"03fc8eaad09d88ef","repo":"different-ai/openwork","slug":"t-providers-not-oauth-flow-prefix-resolve","errorCode":null,"errorMessage":"`${t(\"providers.not_oauth_flow_prefix\")} ${resolved}.`","messagePattern":"`\\$\\{t\\(\"providers\\.not_oauth_flow_prefix\"\\)\\} \\$\\{resolved\\}\\.`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/connections/provider-auth/store.ts","lineNumber":1435,"sourceCode":"\n      const methods = authMethods[resolved];\n      if (!methods || !methods.length) {\n        throw new Error(`${t(\"providers.unknown_provider\")}: ${resolved}`);\n      }\n\n      const oauthIndex =\n        methodIndex !== undefined\n          ? methodIndex\n          : methods.find((method) => method.type === \"oauth\")?.methodIndex ?? -1;\n      if (oauthIndex === -1) {\n        throw new Error(\n          `${t(\"providers.no_oauth_prefix\")} ${resolved}. ${t(\"providers.use_api_key_suffix\")}`,\n        );\n      }\n\n      const selectedMethod = methods.find((method) => method.methodIndex === oauthIndex);\n      if (!selectedMethod || selectedMethod.type !== \"oauth\") {\n        throw new Error(`${t(\"providers.not_oauth_flow_prefix\")} ${resolved}.`);\n      }\n\n      const auth = unwrap(\n        await c.provider.oauth.authorize({ providerID: resolved, method: oauthIndex }),\n      );\n      return { methodIndex: oauthIndex, authorization: auth };\n    } catch (error) {\n      const message = describeProviderError(error, t(\"providers.connect_failed\"));\n      setStateField(\"providerAuthError\", message);\n      throw error instanceof Error ? error : new Error(message);\n    }\n  }\n\n  async function refreshProviders(optionsArg?: { dispose?: boolean; force?: boolean }) {\n    const c = options.client();\n    if (!c) return null;\n\n    if (optionsArg?.dispose) {","sourceCodeStart":1417,"sourceCodeEnd":1453,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/connections/provider-auth/store.ts#L1417-L1453","documentation":"After resolving oauthIndex, startProviderOAuth re-finds the selected method and validates that it exists and its type is exactly \"oauth\" before calling c.provider.oauth.authorize. If the method at that index is missing or has a different type, the store throws not_oauth_flow_prefix. This is a defensive consistency check between the resolved index and the actual method list.","triggerScenarios":"Calling startProviderOAuth with a methodIndex that does not exist in methods (no method has that methodIndex), or that resolves to a method whose type is not \"oauth\" (e.g. 'api'), for providerId `resolved`.","commonSituations":"Hardcoded/stale methodIndex from a previous server response whose ordering changed; cached providerAuthMethods out of sync with the server's current method list; caller passed index 0 assuming OAuth when index 0 is an api-key method; concurrent reconfiguration changed methods between listing and authorize.","solutions":["Omit methodIndex and let the store auto-select the first OAuth method.","Refresh providerAuthMethods from the server and use a methodIndex from the current list.","Verify the method at that index actually has type === \"oauth\" before calling.","Avoid persisting methodIndex across server config changes; re-resolve each session."],"exampleFix":"// before\nawait startProviderOAuth(\"anthropic\", 0); // index 0 is api-key\n// after\nawait startProviderOAuth(\"anthropic\"); // auto-pick first oauth method","handlingStrategy":"validation","validationCode":"const methods = authMethods[providerId] ?? [];\nconst selected = methods.find((m) => m.methodIndex === methodIndex);\nif (!selected || selected.type !== \"oauth\") {\n  // omit methodIndex to auto-select the first oauth method\n  await store.startProviderOAuth(providerId);\n  return;\n}\nawait store.startProviderOAuth(providerId, methodIndex);","typeGuard":"function isOAuthMethod(m: ProviderAuthMethod | undefined): m is ProviderAuthMethod & { type: \"oauth\" } {\n  return m?.type === \"oauth\";\n}","tryCatchPattern":"try {\n  await store.startProviderOAuth(providerId, methodIndex);\n} catch (e) {\n  if (e instanceof Error && /not.{0,5}oauth/i.test(e.message)) {\n    void store.refreshProviderAuthMethods().then(() => store.startProviderOAuth(providerId));\n  } else throw e;\n}","preventionTips":["Prefer omitting methodIndex so the store auto-picks the first OAuth method.","Never persist methodIndex across sessions or server config changes.","Always derive indexes from a freshly fetched method list.","Re-fetch methods if the server may have been reconfigured mid-flow."],"tags":["oauth","validation","indexing"],"backgroundTag":"oauth-not-supported-for-provider","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}