A 401 should not log you out
Short-lived access tokens are good security. Dropping a user back to login in the middle of a payment is not.
The MBS app issues 15-minute access tokens and a longer-lived refresh token. That is a healthy default. The problem was what happened when the access token expired: the next request returned 401, the interceptor gave up, and the user was thrown back to the login screen.
For a guardian halfway through a fee payment, that is not a security feature. It is a lost transaction.
Refresh once, retry once
The response interceptor now refreshes the access token once and replays the original request. A marker on the request config prevents an infinite loop. If the refresh fails, the session is cleared and the user is signed out properly.
Do not mask PIN errors
PIN login and activation also return 401s, but those responses carry meaningful error codes. Refreshing them would hide the reason the PIN was rejected. The interceptor excludes /auth/pin/ endpoints so their own errors reach the UI unchanged.
- Refresh the access token once, then retry the original request.
- Use a request marker so a failed refresh cannot loop forever.
- Exclude login and PIN endpoints from the refresh path.
- Sign out only when the refresh itself fails.
