{"record":{"id":"ef0d1edc4a6738a1","repo":"nextauthjs/next-auth","slug":"option-priority-is-invalid-options-priority","errorCode":null,"errorMessage":"option priority is invalid: ${options.priority}","messagePattern":"option priority is invalid: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core/src/lib/vendored/cookie.ts","lineNumber":337,"sourceCode":"  }\n\n  if (options.priority) {\n    const priority =\n      typeof options.priority === \"string\"\n        ? options.priority.toLowerCase()\n        : undefined\n    switch (priority) {\n      case \"low\":\n        str += \"; Priority=Low\"\n        break\n      case \"medium\":\n        str += \"; Priority=Medium\"\n        break\n      case \"high\":\n        str += \"; Priority=High\"\n        break\n      default:\n        throw new TypeError(`option priority is invalid: ${options.priority}`)\n    }\n  }\n\n  if (options.sameSite) {\n    const sameSite =\n      typeof options.sameSite === \"string\"\n        ? options.sameSite.toLowerCase()\n        : options.sameSite\n    switch (sameSite) {\n      case true:\n      case \"strict\":\n        str += \"; SameSite=Strict\"\n        break\n      case \"lax\":\n        str += \"; SameSite=Lax\"\n        break\n      case \"none\":\n        str += \"; SameSite=None\"","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/core/src/lib/vendored/cookie.ts#L319-L355","documentation":"serialize() accepts `priority` only as one of the strings 'low', 'medium', or 'high' (case-insensitive; the value is lowercased before the switch). Any other truthy value — a misspelled priority, a number, or a non-string object — falls through to the default branch and throws a TypeError. Cookie Priority is a standardized attribute with a closed value set, so anything else is invalid.","triggerScenarios":"serialize(name, val, { priority: 'High ' }) with trailing whitespace is fine after trim but { priority: 'urgent' }, { priority: 1 }, { priority: 'critical' } all throw; also non-lowercase variants are OK ('HIGH' works) but anything outside the three enum values throws.","commonSituations":"Config value mapping where authors assumed other levels exist ('critical', 'normal'); passing a numeric enum instead of a string; upstream data with priorities from a different system; typos like 'hight' or 'meduim'.","solutions":["Use exactly 'low', 'medium', or 'high' (any casing)","Add a TypeScript union type: priority?: 'low' | 'medium' | 'high' so invalid values fail at compile time","Normalize/validate user- or config-supplied priorities against the allowed set before calling serialize","If priority is optional in your logic, omit the field entirely for non-standard values rather than passing a guess"],"exampleFix":"// before\nserialize('sid', val, { priority: 'critical' })\n// after\nserialize('sid', val, { priority: 'high' })","handlingStrategy":"type-guard","validationCode":"const PRIORITIES = new Set(['low', 'medium', 'high'])\nfunction isValidPriority(v) {\n  return typeof v === 'string' && PRIORITIES.has(v.toLowerCase())\n}\nif (opts.priority && !isValidPriority(opts.priority)) throw new TypeError(`option priority is invalid: ${opts.priority}`)","typeGuard":"type CookiePriority = 'low' | 'medium' | 'high'\nfunction isCookiePriority(v: unknown): v is CookiePriority {\n  return typeof v === 'string' && ['low', 'medium', 'high'].includes(v.toLowerCase())\n}","tryCatchPattern":"let cookie\ntry {\n  cookie = serialize('sid', val, { priority })\n} catch (err) {\n  if (err instanceof TypeError && err.message.startsWith('option priority is invalid')) {\n    console.warn(`Dropping invalid priority '${priority}'`)\n    cookie = serialize('sid', val, {})\n  } else throw err\n}","preventionTips":["Use the TypeScript union type priority?: 'low' | 'medium' | 'high' so bad values fail at compile time","Only 'low', 'medium', 'high' exist — map foreign schemes ('critical' -> 'high') explicitly","Avoid trailing/leading whitespace; trim config values before passing","Keep priority as an optional field; omit it rather than guessing a value"],"tags":["cookie","validation","typeerror","serialize","enum"],"backgroundTag":"invalid-cookie-attribute","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}