Changelog - 2026-11-03
roles is optional on the JWT payload
BreakingIn one line. A token may carry no roles. bun check now flags every read of roles that does not check for it first.
What changed
IJWTTokenPayload.rolesis optional (roles?: TJWTTokenRole[]). This one type covers bothgenerate(what you sign) andverify(what you read back).- The role shape has a name:
TJWTTokenRole({ id, identifier, priority }).AuthenticationFieldCodecs.ROLES_CODECis typed with it. - Nothing changes at run time. A token without
roleswas already signed and verified as is. Encryption skips the missing field, and authorization reads the roles as none.
To upgrade
- Run
bun check. - At each place that reads
rolesfrom a payload, handle the missing case, for examplepayload.roles ?? []. - If you signed tokens without roles behind a cast to
IJWTTokenPayload, delete the cast.
Who is affected
- Code that reads
rolesfrom a verified token or fromAuthentication.CURRENT_USERtyped asIJWTTokenPayload. This is a type-only break, andbun checklists each place. - Code that typed a codec as
IPayloadFieldCodec<IJWTTokenPayload['roles']>. UseIPayloadFieldCodec<TJWTTokenRole[]>. - Everyone else. No action needed.