{"record":{"id":"5ea1fdbf4b2f462b","repo":"mastra-ai/mastra","slug":"supabase-url-and-anon-key-are-required-please-pro","errorCode":null,"errorMessage":"Supabase URL and anon key are required, please provide them in the options or set the environment variables SUPABASE_URL and SUPABASE_ANON_KEY","messagePattern":"Supabase URL and anon key are required, please provide them in the options or set the environment variables SUPABASE_URL and SUPABASE_ANON_KEY","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"auth/supabase/src/index.ts","lineNumber":22,"sourceCode":"import { createClient } from '@supabase/supabase-js';\nimport type { SupabaseClient, User } from '@supabase/supabase-js';\n\ninterface MastraAuthSupabaseOptions extends MastraAuthProviderOptions<User> {\n  url?: string;\n  anonKey?: string;\n}\n\nexport class MastraAuthSupabase extends MastraAuthProvider<User> {\n  protected supabase: SupabaseClient;\n\n  constructor(options?: MastraAuthSupabaseOptions) {\n    super({ name: options?.name ?? 'supabase' });\n\n    const supabaseUrl = options?.url ?? process.env.SUPABASE_URL;\n    const supabaseAnonKey = options?.anonKey ?? process.env.SUPABASE_ANON_KEY;\n\n    if (!supabaseUrl || !supabaseAnonKey) {\n      throw new Error(\n        'Supabase URL and anon key are required, please provide them in the options or set the environment variables SUPABASE_URL and SUPABASE_ANON_KEY',\n      );\n    }\n\n    this.supabase = createClient(supabaseUrl, supabaseAnonKey);\n\n    this.registerOptions(options);\n  }\n\n  async authenticateToken(token: string): Promise<User | null> {\n    const { data, error } = await this.supabase.auth.getUser(token);\n\n    if (error) {\n      return null;\n    }\n\n    return data.user;\n  }","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/auth/supabase/src/index.ts#L4-L40","documentation":"The Supabase auth provider requires a project URL and anon key to create its Supabase client. Both are resolved from options.url/options.anonKey or SUPABASE_URL/SUPABASE_ANON_KEY. If either is missing, construction throws because the provider cannot function without a client.","triggerScenarios":"`new MastraAuthSupabase(options)` (or super() in the provider) where url or anonKey is undefined and the matching SUPABASE_URL / SUPABASE_ANON_KEY env vars are unset or empty.","commonSituations":"Missing .env loading in the server entrypoint; env vars not copied to the deployment; using the service key var name (SUPABASE_SERVICE_KEY) instead of SUPABASE_ANON_KEY; typo in option key (e.g. {supabaseUrl}).","solutions":["Set both SUPABASE_URL and SUPABASE_ANON_KEY environment variables","Pass them explicitly: new MastraAuthSupabase({ url: 'https://xyz.supabase.co', anonKey: '...' })","Confirm dotenv/config or platform env loading runs before provider construction","Copy the correct values from Supabase dashboard > Project Settings > API"],"exampleFix":"// before\nconst auth = new MastraAuthSupabase({ url: process.env.SUPABASE_URL });\n// after\nconst auth = new MastraAuthSupabase({\n  url: process.env.SUPABASE_URL,\n  anonKey: process.env.SUPABASE_ANON_KEY,\n});","handlingStrategy":"validation","validationCode":"function assertSupabaseConfig(opts) {\n  const url = opts?.url ?? process.env.SUPABASE_URL;\n  const key = opts?.anonKey ?? process.env.SUPABASE_ANON_KEY;\n  if (!url || !key) throw new Error('Supabase config missing: set SUPABASE_URL and SUPABASE_ANON_KEY');\n  if (!url.startsWith('https://') || !url.includes('.supabase.co')) throw new Error('SUPABASE_URL is not a valid Supabase project URL');\n  return { url, key };\n}","typeGuard":"function hasSupabaseOptions(o) {\n  return typeof o === 'object' && o !== null &&\n    typeof o.url === 'string' && o.url.length > 0 &&\n    typeof o.anonKey === 'string' && o.anonKey.length > 0;\n}","tryCatchPattern":"let auth;\ntry {\n  auth = new MastraAuthSupabase(options);\n} catch (e) {\n  if (e.message.includes('Supabase URL and anon key')) {\n    throw new ConfigError('Missing SUPABASE_URL / SUPABASE_ANON_KEY — check env loading');\n  }\n  throw e;\n}","preventionTips":["Load dotenv before any provider construction in the entrypoint","Validate both vars in a startup config check","Copy values from Supabase dashboard > Project Settings > API, not from memory","Keep anon key and service key vars clearly named to avoid mixups"],"tags":["config","env-var","supabase","constructor"],"backgroundTag":"missing-env-var","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}