fix(auth): type the registration ttl as a number - #27
Merged
Conversation
RegistrationSuccessSchema.ttl was z.string(), describing what the auth API sent rather than what the value is. It was the only ttl in the auth schemas a consumer could not treat like the others. That had a real consequence. The Fastify adapter hands the value to a cookie library that requires an integer, so registration failed there with `TypeError: option maxAge is invalid: 300`. The Express adapter multiplies it into milliseconds, which coerces the string, so the same response worked and the mismatch stayed hidden. Breaking for anyone reading the field as a string. Taken as a minor because the package is pre-1.0. Verified with npm run typecheck, npm test (162 passing), npm run lint, and npm run format:check.
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First of three. Fixes a real failure reported testing the Fastify API template.
The bug
Registration fails on Fastify with:
cookiechecksNumber.isInteger(maxAge).300as a number passes, so the value reaching it is the string"300"(the error interpolates without quotes).Why the contract is at fault
RegistrationSuccessSchema.ttlwasz.string(), describing what the API happened to send rather than what the value is. Every otherttlin this file isz.number(), which made this the only one a consumer could not treat like the rest.The adapters then diverged on it:
maxAge: maxAgeSeconds * 1000"300" * 1000 === 300000, the multiply coerces, worksmaxAge: maxAgeSecondscookie,Number.isIntegerfails, throwsSo the Express adapter has been masking this the whole time.
One thing I checked that is not affected:
signSessionCookiebuildsexpiresIn: \${ttlSeconds}s`, so"300"interpolates to"300s"` exactly as the number would. No JWT lifetime bug, the damage is confined to the Fastify cookie throw.Versioning
Marked minor, not major. This is a breaking contract change, but the package is pre-1.0 and a major here would mint 1.0.0, which this does not warrant. The changeset says plainly that it breaks anyone reading the field as a string.
Tests
Three added: a numeric
ttlparses, a stringttlis rejected the wayLoginSuccessResponseSchemaalready rejects one, and the field stays optional.Verification
npm run typecheck,npm test(162 passing),npm run lint,npm run format:checkall clean.The rest of the fix
seamless-auth-api: stop sending'300'(blocked on this release, since response bodies are validated against this schema at runtime)seamless-auth-server: parse the value at core's untyped upstream boundary, so no adapter can diverge on it again