Skip to content

feat(zero-rust,zero-swift): connection.connect takes ConnectAuth and fails like JS - #215

Open
tmm wants to merge 1 commit into
mainfrom
feat/zero-connect-auth
Open

tmm wants to merge 1 commit into
mainfrom
feat/zero-connect-auth

Conversation

@tmm

@tmm tmm commented Nov 14, 2026

Copy link
Copy Markdown
Member

tmm's decision 1(b): connection.connect takes a ConnectAuth and fails like JS, in both clients, with the same shape.

zero.connection().connect(ConnectAuth::Set(token))?;   // or Keep, Clear
try zero.connection.connect(.set(token))                // or .keep (the default), .clear
  • Invalid pair (a non-empty token with no userID): fails at once, kind Internal, "ZeroOptions.userID is required when auth is set." (JS's #setAuth). Nothing is set or sent. Before, both clients only logged connect(auth:) ignored.
  • Clear drops the token, as JS's auth: null does. Before, neither client could clear it.
  • Unchanged: the NoSocketOrigin early return, resuming only from a terminal state, and updateAuth while connected. Both stay synchronous; subscribe follows the state.
  • Vector connect steps map absent, null, and string to Keep, Clear, and Set, as the JS harness passes them.

Changesets:

  • zero-rust minor.
  • zero-swift minor: removing connect(auth:) breaks Swift's API, and scripts/api-breaks.sh passes only with a minor bump below 1.0. Swift's next release would be 0.8.0.

Tests: rust/zero-client/tests/connect_auth.rs and HardenConnectionTests.connectWithAuthOnALoggedOutClientThrowsAndClearDropsTheToken. Both fail when Clear is mapped to Keep.

Checked locally:

  • Rust: clippy -D warnings, tests, docs, and conformance (66,384 cases, 0 failures).
  • Swift: format lint, ZeroTests (162 passed), ConformanceTests (67 passed), and api-breaks.sh (allowed by the minor changeset).

…and fail like JS

JS's `connection.connect({auth})` rejects before it does anything when
the client has no userID and the token is non-empty, and `auth: null`
clears the token. The Rust and Swift clients only logged the invalid
pair and ignored the call, and had no way to clear the token.

Rust's `Connection::connect` now takes `ConnectAuth { Keep, Set(String),
Clear }` and returns `Result<(), Error>`; Swift's `connect(_:)` takes
`ConnectAuth { keep, set(String), clear }` and throws. An invalid pair is
the Internal error "ZeroOptions.userID is required when auth is set."
and changes nothing. Both stay synchronous: `subscribe` follows the
state. The conformance runners map a vector's absent, null, and string
`auth` to Keep, Clear, and Set, as the JS harness passes them.

Swift's `connect(auth:)` is gone, an API break below 1.0 that the minor
changeset declares.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants