{"record":{"id":"c7427d0ed4f98a0c","repo":"payloadcms/payload","slug":"no-auth-config-found-for-collection-collection","errorCode":null,"errorMessage":"No auth config found for collection: ${collection}","messagePattern":"No auth config found for collection: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/payload/src/auth/serverFunctions/login.ts","lineNumber":48,"sourceCode":"\n/**\n * Logs a user in and writes the auth cookie through the supplied `serverAdapter`,\n * so the function is framework-agnostic; each adapter binds its own.\n */\nexport async function login<TSlug extends AuthCollectionSlug>({\n  collection,\n  config,\n  email,\n  password,\n  serverAdapter,\n  username,\n}: LoginArgs<TSlug>): Promise<LoginResult<TSlug>> {\n  const payload = await getPayload({ config, cron: true })\n\n  const authConfig = payload.collections[collection]?.config.auth\n\n  if (!authConfig) {\n    throw new Error(`No auth config found for collection: ${collection}`)\n  }\n\n  const loginWithUsername = authConfig.loginWithUsername ?? false\n\n  if (loginWithUsername) {\n    if (loginWithUsername.allowEmailLogin) {\n      if (!email && !username) {\n        throw new Error('Email or username is required.')\n      }\n    } else {\n      if (!username) {\n        throw new Error('Username is required.')\n      }\n    }\n  } else {\n    if (!email) {\n      throw new Error('Email is required.')\n    }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/auth/serverFunctions/login.ts#L30-L66","documentation":"Thrown in the server-function `login` when `payload.collections[collection]?.config.auth` is falsy. Either the collection slug does not exist on the resolved Payload instance, or it exists but is not an auth-enabled collection. This is a plain `Error` (not an `APIError`), so it has no HTTP status — it surfaces wherever the adapter calls `login()`.","triggerScenarios":"The adapter's `login({ collection, ... })` is called with a slug that is misspelled, not registered in `config.collections`, or registered without `auth: true`. The lookup `payload.collections[collection]` returns undefined (`.config.auth` → undefined).","commonSituations":"Frontend hard-codes a collection slug that was renamed in config; a collection was removed but the auth UI still references it; `auth` was not set on the collection config (it's a content collection, not an auth collection); config loaded asynchronously and `getPayload` resolved a stale/partial instance.","solutions":["Confirm the slug exists in `config.collections` and the collection is declared with `auth: true` (or `auth: {...}`).","Use the typed `AuthCollectionSlug` to catch slug typos at compile time.","Ensure `getPayload({ config })` receives the same config that defines the collection.","After adding/renaming a collection, rebuild and restart so the slug resolves."],"exampleFix":"// before\nawait login({ collection: 'admins', config, password, email, serverAdapter })\n// after — verify the slug is a registered auth collection\nif (!payload.collections['users']?.config.auth) {\n  throw new Error('Configuration error: users collection is not auth-enabled')\n}\nawait login({ collection: 'users', config, password, email, serverAdapter })","handlingStrategy":"validation","validationCode":"// Verify the collection is a registered auth collection before login\nconst payload = await getPayload({ config })\nconst authConfig = payload.collections[collection]?.config.auth\nif (!authConfig) {\n  throw new Error(`Collection ${String(collection)} is not an auth collection`)\n}\nawait login({ collection, config, email, password, serverAdapter })","typeGuard":"function isAuthCollection(payload: Payload, slug: string): slug is AuthCollectionSlug {\n  return !!payload.collections[slug]?.config.auth\n}","tryCatchPattern":"// Plain Error (not APIError) — catch broadly and report config error\ntry {\n  await login({ collection, config, email, password, serverAdapter })\n} catch (e) {\n  if (e instanceof Error && /No auth config/.test(e.message)) {\n    // surface a configuration error to the operator\n  } else throw e\n}","preventionTips":["Use the typed `AuthCollectionSlug` so slug typos fail at compile time.","Confirm the collection is declared with `auth: true` in config.","Pass the same `config` to `getPayload`/`login` that defines the collection."],"tags":["auth","login","config","server-function"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}