{"record":{"id":"9d32dedd76a80601","repo":"mastra-ai/mastra","slug":"google-client-id-is-required-provide-it-in-the-op","errorCode":null,"errorMessage":"Google client ID is required. Provide it in the options or set GOOGLE_CLIENT_ID environment variable.","messagePattern":"Google client ID is required\\. Provide it in the options or set GOOGLE_CLIENT_ID environment variable\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/google/src/auth-provider.ts","lineNumber":239,"sourceCode":"  protected clientId: string;\n  private clientSecret: string | null;\n  private redirectUri: string | null;\n  private scopes: string[];\n  private cookieName: string;\n  private cookieMaxAge: number;\n  private cookiePassword: string;\n  private secureCookies: boolean;\n  private allowedDomains: string[];\n  private hostedDomain?: string;\n  private ssoEnabled: boolean;\n  private jwks: ReturnType<typeof createRemoteJWKSet>;\n\n  constructor(options?: MastraAuthGoogleOptions) {\n    super({ name: options?.name ?? 'google' });\n\n    const clientId = options?.clientId ?? process.env.GOOGLE_CLIENT_ID;\n    if (!clientId) {\n      throw new Error(\n        'Google client ID is required. Provide it in the options or set GOOGLE_CLIENT_ID environment variable.',\n      );\n    }\n\n    const allowedDomains = normalizeAllowedDomains(options?.allowedDomains ?? process.env.GOOGLE_ALLOWED_DOMAINS);\n    const configuredHostedDomain = normalizeDomain(options?.hostedDomain ?? process.env.GOOGLE_HOSTED_DOMAIN);\n    const clientSecret = options?.clientSecret ?? process.env.GOOGLE_CLIENT_SECRET;\n    const redirectUri = options?.redirectUri ?? process.env.GOOGLE_REDIRECT_URI;\n    const hasConfiguredCookiePassword = !!(options?.session?.cookiePassword ?? process.env.GOOGLE_COOKIE_PASSWORD);\n    const cookiePassword =\n      options?.session?.cookiePassword ??\n      process.env.GOOGLE_COOKIE_PASSWORD ??\n      crypto.randomUUID() + crypto.randomUUID();\n\n    this.clientId = clientId;\n    this.clientSecret = clientSecret ?? null;\n    this.redirectUri = redirectUri ?? null;\n    this.scopes = options?.scopes ?? DEFAULT_SCOPES;","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/auth/google/src/auth-provider.ts#L221-L257","documentation":"The MastraAuthGoogle constructor requires a Google OAuth client ID. It reads options.clientId first, then falls back to the GOOGLE_CLIENT_ID environment variable. If neither is set it cannot initialize the provider, so it throws immediately at construction time rather than failing later mid-request.","triggerScenarios":"new MastraAuthGoogle() or new MastraAuthGoogle({ name: 'google' }) with no clientId in the options object while process.env.GOOGLE_CLIENT_ID is undefined (not set, or set only after the process started / in a different environment).","commonSituations":"Deploying to production/cloud where the .env file isn't copied; forgetting to configure GOOGLE_CLIENT_ID in the hosting platform's env settings; loading dotenv after the provider is instantiated; a typo like GOOGLE_CLIENTID.","solutions":["Set the GOOGLE_CLIENT_ID environment variable in the environment where the server runs.","Or pass clientId explicitly: new MastraAuthGoogle({ clientId: 'xxx.apps.googleusercontent.com' }).","Ensure dotenv/config is loaded before the provider module is imported/instantiated.","Confirm the value in your OAuth/OIDC console matches (Google Cloud Console > Credentials > OAuth 2.0 Client ID)."],"exampleFix":"// before\nconst auth = new MastraAuthGoogle({});\n\n// after\nconst auth = new MastraAuthGoogle({\n  clientId: process.env.GOOGLE_CLIENT_ID,\n});","handlingStrategy":"validation","validationCode":"if (!options?.clientId && !process.env.GOOGLE_CLIENT_ID) {\n  throw new Error('Set GOOGLE_CLIENT_ID before constructing MastraAuthGoogle');\n}\nconst auth = new MastraAuthGoogle(options);","typeGuard":"function hasGoogleClientId(o?: { clientId?: string }): o is { clientId: string } & typeof o {\n  return typeof o?.clientId === 'string' && o.clientId.length > 0;\n}","tryCatchPattern":"try {\n  const auth = new MastraAuthGoogle(options);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('client ID is required')) {\n    console.error('Missing GOOGLE_CLIENT_ID — check env config for this environment');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Set GOOGLE_CLIENT_ID in every environment (CI, staging, prod) via your platform's secret manager.","Load dotenv (or equivalent) before importing/instantiating the provider.","Fail fast at boot: construct the provider at startup, not lazily per-request.","Validate required env vars with a startup checklist or schema (e.g. zod on process.env)."],"tags":["configuration","oauth","google","env-var","startup"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}