{"record":{"id":"f5f9017f4f5cf3b6","repo":"nextauthjs/next-auth","slug":"dgraph-client-error-please-provide-an-api-key","errorCode":null,"errorMessage":"Dgraph client error: Please provide an API key","messagePattern":"Dgraph client error: Please provide an API key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/adapter-dgraph/src/lib/client.ts","lineNumber":37,"sourceCode":"  /**\n   * @default \"Authorization\"\n   *\n   * [Using JWT and authorization claims](https://dgraph.io/docs/graphql/authorization/authorization-overview#using-jwts-and-authorization-claims)\n   */\n  authHeader?: string\n}\n\nexport class DgraphClientError extends Error {\n  name = \"DgraphClientError\"\n  constructor(errors: any[], query: string, variables: any) {\n    super(errors.map((error) => error.message).join(\"\\n\"))\n    console.error({ query, variables })\n  }\n}\n\nexport function client(params: DgraphClientParams) {\n  if (!params.authToken) {\n    throw new Error(\"Dgraph client error: Please provide an API key\")\n  }\n  if (!params.endpoint) {\n    throw new Error(\n      \"Dgraph client error: Please provide a valid GraphQL endpoint\"\n    )\n  }\n\n  const {\n    endpoint,\n    authToken,\n    jwtSecret,\n    jwtAlgorithm = \"HS256\",\n    authHeader = \"Authorization\",\n  } = params\n  const headers: HeadersInit = {\n    \"Content-Type\": \"application/json\",\n    \"X-Auth-Token\": authToken,\n  }","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/adapter-dgraph/src/lib/client.ts#L19-L55","documentation":"The Dgraph adapter's client() factory validates its params before building the GraphQL client and throws if authToken is missing. Dgraph Cloud requires an API key for authorization, so the adapter refuses to construct a client without one. This is a configuration-time error thrown synchronously when the adapter is created.","triggerScenarios":"Calling DgraphAdapter({ endpoint }) (or DgraphClient) without params.authToken, or with authToken set to an empty string/undefined from a missing env var.","commonSituations":"DGRAPH_AUTH_TOKEN (or equivalent) env var not set in the deployment (Cloudflare Workers secrets, Vercel env), typo in the env var name, or hardcoding params without the token in local dev.","solutions":["Set the authToken param: DgraphAdapter({ endpoint: process.env.DGRAPH_ENDPOINT, authToken: process.env.DGRAPH_AUTH_TOKEN }).","Configure the env var/secret in your hosting platform (wrangler secret put, .env.local, etc.).","Check for typos or falsy empty-string values in the token variable."],"exampleFix":"// before\nconst adapter = DgraphAdapter({ endpoint: process.env.DGRAPH_ENDPOINT })\n// after\nconst adapter = DgraphAdapter({\n  endpoint: process.env.DGRAPH_ENDPOINT,\n  authToken: process.env.DGRAPH_AUTH_TOKEN,\n})","handlingStrategy":"validation","validationCode":"if (!process.env.DGRAPH_AUTH_TOKEN) {\n  throw new Error('DGRAPH_AUTH_TOKEN must be set before initializing the Dgraph adapter')\n}","typeGuard":"function hasDgraphParams(p: unknown): p is Required<DgraphClientParams> {\n  return !!p && typeof p === 'object' && typeof (p as any).authToken === 'string' && (p as any).authToken.length > 0\n}","tryCatchPattern":"try {\n  const adapter = DgraphAdapter(params)\n} catch (e) {\n  if (e instanceof Error && e.message.includes('Please provide an API key')) {\n    // fail fast at startup: check env var name and deployment secrets\n  }\n  throw e\n}","preventionTips":["Set DGRAPH_AUTH_TOKEN in every environment (dev, preview, prod)","On Workers/Vercel, configure secrets via wrangler secret put or dashboard","Fail fast with a startup check before constructing the adapter","Never hardcode the token; always read from environment"],"tags":["configuration","api-key","dgraph","env"],"backgroundTag":"missing-env-var","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}