nextauthjs/next-auth · error · TypeError
option priority is invalid: ${options.priority}
Error message
option priority is invalid: ${options.priority} What it means
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.
Source
Thrown at packages/core/src/lib/vendored/cookie.ts:337
}
if (options.priority) {
const priority =
typeof options.priority === "string"
? options.priority.toLowerCase()
: undefined
switch (priority) {
case "low":
str += "; Priority=Low"
break
case "medium":
str += "; Priority=Medium"
break
case "high":
str += "; Priority=High"
break
default:
throw new TypeError(`option priority is invalid: ${options.priority}`)
}
}
if (options.sameSite) {
const sameSite =
typeof options.sameSite === "string"
? options.sameSite.toLowerCase()
: options.sameSite
switch (sameSite) {
case true:
case "strict":
str += "; SameSite=Strict"
break
case "lax":
str += "; SameSite=Lax"
break
case "none":
str += "; SameSite=None"View on GitHub (pinned to a1a16a5a77)
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
Example fix
// before
serialize('sid', val, { priority: 'critical' })
// after
serialize('sid', val, { priority: 'high' }) Defensive patterns
Strategy: type-guard
Validate before calling
const PRIORITIES = new Set(['low', 'medium', 'high'])
function isValidPriority(v) {
return typeof v === 'string' && PRIORITIES.has(v.toLowerCase())
}
if (opts.priority && !isValidPriority(opts.priority)) throw new TypeError(`option priority is invalid: ${opts.priority}`) Type guard
type CookiePriority = 'low' | 'medium' | 'high'
function isCookiePriority(v: unknown): v is CookiePriority {
return typeof v === 'string' && ['low', 'medium', 'high'].includes(v.toLowerCase())
} Try / catch
let cookie
try {
cookie = serialize('sid', val, { priority })
} catch (err) {
if (err instanceof TypeError && err.message.startsWith('option priority is invalid')) {
console.warn(`Dropping invalid priority '${priority}'`)
cookie = serialize('sid', val, {})
} else throw err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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'.
Related errors
- option domain is invalid: ${options.domain}
- option path is invalid: ${options.path}
- option expires is invalid: ${options.expires}
- option sameSite is invalid: ${options.sameSite}
- argument name is invalid: ${name}
AI-assisted analysis of nextauthjs/next-auth@a1a16a5a77 (2026-08-28).
Data as JSON: /api/errors/ef0d1edc4a6738a1.
Report an issue: GitHub.