{"record":{"id":"fd78cd4602d17181","repo":"cube-js/cube","slug":"options-checksqlauth-must-be-a-function","errorCode":null,"errorMessage":"options.checkSqlAuth must be a function","messagePattern":"options\\.checkSqlAuth must be a function","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-native/js/index.ts","lineNumber":396,"sourceCode":"};\n\nexport type SqlInterfaceInstance = { __typename: 'sqlinterfaceinstance' };\n\nexport const registerInterface = async (options: SQLInterfaceOptions): Promise<SqlInterfaceInstance> => {\n  if (typeof options !== 'object' && options == null) {\n    throw new Error('Argument options must be an object');\n  }\n\n  if (typeof options.contextToApiScopes !== 'function') {\n    throw new Error('options.contextToApiScopes must be a function');\n  }\n\n  if (typeof options.checkAuth !== 'function') {\n    throw new Error('options.checkAuth must be a function');\n  }\n\n  if (typeof options.checkSqlAuth !== 'function') {\n    throw new Error('options.checkSqlAuth must be a function');\n  }\n\n  if (typeof options.meta !== 'function') {\n    throw new Error('options.meta must be a function');\n  }\n\n  if (typeof options.stream !== 'function') {\n    throw new Error('options.stream must be a function');\n  }\n\n  if (typeof options.sqlApiLoad !== 'function') {\n    throw new Error('options.sqlApiLoad must be a function');\n  }\n\n  if (typeof options.sqlGenerators !== 'function') {\n    throw new Error('options.sqlGenerators must be a function');\n  }\n","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-native/js/index.ts#L378-L414","documentation":"registerInterface requires a checkSqlAuth function that authenticates SQL API connections (user/password for the Postgres-style SQL endpoint). Without it, SQL sessions cannot be authorized, so the options are rejected.","triggerScenarios":"Calling registerInterface() with an options object whose checkSqlAuth property is missing or not a function.","commonSituations":"Setting up the SQL API through the native planner but only configuring REST-side auth; copying example code predating the checkSqlAuth requirement; typo like checkSqlAuth vs checkSqlAuth.","solutions":["Add checkSqlAuth, e.g. async (username, password) => ({ password }), resolving the user's security context.","Wire it to the same JWT verification your checkAuth uses, returning the expected password for the SQL client.","Confirm no conditional branches assign checkSqlAuth only sometimes."],"exampleFix":"// before\nawait registerInterface({ contextToApiScopes, checkAuth, meta, stream });\n\n// after\nawait registerInterface({\n  contextToApiScopes, checkAuth,\n  checkSqlAuth: async (user, password) => ({ password }),\n  meta, stream\n});","handlingStrategy":"validation","validationCode":"if (typeof options.checkSqlAuth !== 'function') {\n  throw new Error('options.checkSqlAuth must be provided as a function');\n}","typeGuard":"function hasCheckSqlAuth(o) {\n  return typeof o?.checkSqlAuth === 'function';\n}","tryCatchPattern":"try {\n  await registerInterface(options);\n} catch (e) {\n  if (e.message === 'options.checkSqlAuth must be a function') {\n    console.error('Provide checkSqlAuth: async (user, password) => ({ password }).');\n  } else throw e;\n}","preventionTips":["When enabling the SQL API, configure both REST (checkAuth) and SQL (checkSqlAuth) handlers together.","Centralize SQL auth in one exported function and unit-test it.","Use the typed options interface so missing callbacks fail compilation, not runtime."],"tags":["validation","callback","sql-auth","sql-interface"],"backgroundTag":"missing-required-callback","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}