[PR #47] Unlinking Logins and the Withdrawal Request Server
- What changed: Four endpoints were added to the server so that a user can unlink a login and request withdrawal inside the app.
- Decision: The outside link is removed first, and our record is kept if that fails. A withdrawal request gives the same result even if it arrives twice.
- Still unknown: How the outside service answers a link that is already removed was not confirmed with a real response.
PR #47 is the record of building the server side that lets the app unlink a login method and request withdrawal. It was not agent-led work. It ran in a cloud session.
What was done and why
- App store rules require that unlinking a login and requesting withdrawal can be done inside the app.
- Following the server plan’s task 10, four endpoints were built: list linked login methods, unlink one, view a withdrawal request, and make a withdrawal request.
Options considered
- The outside link is removed first, and our record is kept if that fails. The other order would delete our record while the outside service still keeps the link. The user would think the link is gone when it is not.
- Failure responses were split. If the outside service is temporarily unavailable, the response says to try again later. Other failures say which side failed. This lets the app tell “try later” apart from “failed”.
- The person’s record row is locked so two requests cannot overlap. If someone with only two login methods removes both at once, both could pass the check “at least one must remain” and leave none. The row is locked during removal so the requests line up.
- Rejected: counting again after the outside call. The second request would then remove the outside link but leave our record, an in-between state.
- Cost: the lock is held during the outside call. Since the number of users is small, this was judged acceptable, and reviewers were asked to confirm it.
- The checks run in a set order. A method that belongs to someone else is reported as not found. If it is the only one, the request says it cannot be removed. A phone-number method gets its own message. For a person with only a phone number, “it is the only one” is the more accurate message, so that check comes first.
- A withdrawal request gives the same result if sent twice. The first request creates the record. If an unprocessed request already exists, the existing one is returned. The same row lock blocks the duplicate. A database uniqueness error would also catch duplicates, but that approach was longer, so it was not used.
How it was checked
- The tests were committed first. Ten new tests were seen failing because the endpoints did not exist yet, and then the code was written.
- The fake outside clients were set to fail in different ways, so the failure paths were tested too.
- After the change, the eleven related tests and the full project check passed.
- In the cloud environment, pulling the test database image hit a rate limit once. Pulling it again worked.
Not yet checked
- How the outside service answers when a link is already removed has not been checked against its real responses. A person will check this once the real keys are ready.
- The lock approach needs a review if the number of users grows.
Lessons
- When an outside record and our record change together, change the outside one first. If that fails, leave our record as it was.
- If two requests can change the same record at once, a rule check can still fail after it passes. Locking the same row was the simplest guard.
- Making a repeated request return the same result means the app can retry safely.