{"record":{"id":"a4729e2670d16038","repo":"dubinc/dub","slug":"access-token-not-found-please-run-dub-login-to","errorCode":null,"errorMessage":"Access token not found. Please run `dub login` to authenticate with Dub.","messagePattern":"Access token not found\\. Please run `dub login` to authenticate with Dub\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/config.ts","lineNumber":9,"sourceCode":"import type { DubConfig } from \"@/types\";\nimport { oauthClient } from \"@/utils/oauth\";\nimport Configstore from \"configstore\";\n\nexport async function getConfig(): Promise<DubConfig> {\n  const configStore = new Configstore(\"dub-cli\");\n\n  if (!configStore.size) {\n    throw new Error(\n      \"Access token not found. Please run `dub login` to authenticate with Dub.\",\n    );\n  }\n\n  const config = configStore.all as DubConfig;\n\n  if (config.expires_at && Date.now() >= config.expires_at) {\n    const { accessToken, refreshToken, expiresAt } =\n      await oauthClient.refreshToken({\n        accessToken: config.access_token,\n        refreshToken: config.refresh_token,\n        expiresAt: config.expires_at,\n      });\n\n    return await setConfig({\n      access_token: accessToken,\n      refresh_token: refreshToken,\n      expires_at: expiresAt,","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/dubinc/dub/blob/f216b94a24ca5a0a48c6543ee10392c9006c8b75/packages/cli/src/utils/config.ts#L1-L27","documentation":"getConfig reads the dub-cli config store (via Configstore); if it is empty, no access token has ever been saved by `dub login`. The CLI throws this to stop any authenticated API call before making a request without credentials. It means the local machine has no stored Dub credentials, not that a token is expired or invalid.","triggerScenarios":"Any CLI command that calls getConfig (e.g. `dub link`/shorten, `dub config`, `dub domains`) when the configstore file for 'dub-cli' is empty or missing (configStore.size is falsy).","commonSituations":"Fresh install of @dub/analytics-cli without running `dub login`; running the CLI in CI/containers or on a new machine where the home-dir config was never created; different user/HOME so the config file is not found.","solutions":["Run `dub login` and paste an access token from app.dub.co to populate the config store.","Verify the config file exists (Configstore stores it in ~/.config/configstore/dub-cli.json or platform equivalent) and is non-empty.","In CI, create the config file as a setup step (echo JSON with accessToken into the configstore path) before running commands.","Ensure the same OS user/HOME is used that originally ran `dub login`."],"exampleFix":"// before\nnpx dub-cli link https://example.com  // Error: Access token not found...\n// after\ndub login   # paste token\nnpx dub-cli link https://example.com","handlingStrategy":"validation","validationCode":"import { getConfig } from \"@/utils/config\";\n// or check the file directly before invoking CLI commands\nimport fs from \"fs\";\nimport path from \"path\";\nconst cfgPath = path.join(process.env.XDG_CONFIG_HOME ?? path.join(process.env.HOME ?? \"\", \".config\"), \"configstore\", \"dub-cli.json\");\nconst loggedIn = fs.existsSync(cfgPath) && fs.statSync(cfgPath).size > 0;\nif (!loggedIn) throw new Error(\"Run `dub login` before running this command\");","typeGuard":"function hasToken(config: unknown): config is { accessToken: string } {\n  return typeof config === \"object\" && config !== null && \"accessToken\" in config && typeof (config as any).accessToken === \"string\" && (config as any).accessToken.length > 0;\n}","tryCatchPattern":"try {\n  const cfg = await getConfig();\n  // use cfg\n} catch (e) {\n  if ((e as Error).message.includes(\"Access token not found\")) {\n    console.error(\"Not authenticated. Run `dub login` first.\");\n    process.exitCode = 1;\n  } else throw e;\n}","preventionTips":["Run `dub login` immediately after installing the CLI.","In CI, provision the configstore file as a pre-step with a token from secrets.","Pin a consistent HOME/user across pipeline steps so the config persists.","Document the login prerequisite in project onboarding docs."],"tags":["authentication","cli","missing-credentials"],"backgroundTag":"missing-credentials","analyzedSha":"f216b94a24ca5a0a48c6543ee10392c9006c8b75","analyzedAt":"2026-08-31T18:35:50.395Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}