Repository navigation
fix: Revoke API token when account creation fails - #2083
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Failed web login for an already-connected user can revoke their existing session and delete cached drives and File Provider domains because rollback is not restricted to the session created by that attempt.
1 open issue
What changed in this PR
This PR centralizes failed-login cleanup in AccountManager to revoke newly issued API tokens when account setup fails.
Changes:
- Wraps account creation in shared error handling that cleans up account state, requests token revocation, and rethrows the error.
- Extracts a reusable token-revocation helper.
- Removes branch-specific cleanup; late failures such as root initialization now also log the account out.
| File | Description |
|---|---|
kDriveCore/Data/Cache/AccountManager.swift |
Centralizes account-creation failure cleanup and shares token-revocation logic. |
Review effort: Balanced
45dbfeb to
45bea5c
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Failed login cleanup can revoke an already-connected account’s valid token and delete its local data instead of limiting rollback to state owned by the failed attempt and separately revoking the newly issued token.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
45bea5c to
32f711b
Compare
|
adrien-coye
left a comment
There was a problem hiding this comment.
Discussed with @PhilippeWeidmann what was the goal of this PR.
Checked that inedded it does not impact the log-out policy on a server outage.
I check the log-out behaviour with some sample code.




When login returns an API token but a later step of account creation fails (fetching the user profile, fetching drives, no usable drive, initializing the root, etc.), the new token was not always revoked and stayed valid server-side.
Same approach as Infomaniak/ios-kMail#2375 and Infomaniak/ios-euria#145:
createAndSetCurrentAccount(token:)indo/catch. On any error, remove the token and account fortoken.userId, revoke the token, then rethrow.private func revokeApiToken(_:)from the existing remove-account path and reuse it.catchnow covers them.Note for review: a failure late in the flow (e.g.
initRoot()) now also logs the account out, whereas before it stayed logged in.