Skip to content

Commit cbb01af

Browse files
nan-liclaude
andcommitted
fix(iv): wake queue on login(sameId, freshJwt) refresh path
Same-user-id login with a fresh JWT (the documented post-401 refresh path) was storing the new token but never calling forceExecuteOperations, so ops parked by hasValidJwtIfRequired stayed deferred until something else woke the queue. updateUserJwt already does this correctly; reference #2599 LoginHelper does too. Match that design — drop redundant if (jwtBearerToken != null) guards (putJwt no-ops on null) and call forceExecuteOperations unconditionally on the same-id branch so the queue drains as soon as the developer supplies a fresh token. Extend the existing same-id+JWT test to verify forceExecuteOperations fires. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1e8d3f2 commit cbb01af

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/LoginHelper.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,18 @@ internal class LoginHelper(
3737
val currentOneSignalId = identityModelStore.model.onesignalId
3838

3939
if (currentExternalId == externalId) {
40-
// Even when no user-switch happens, an updated JWT for the same externalId
41-
// should be stored so subsequent requests use the fresh token.
42-
if (jwtBearerToken != null) {
43-
jwtTokenStore.putJwt(externalId, jwtBearerToken)
44-
}
40+
// Same-user refresh path (e.g. login(sameId, freshJwt) after a 401). Store the
41+
// fresh token and wake the queue so any ops deferred by `hasValidJwtIfRequired`
42+
// dispatch immediately — symmetric with `updateUserJwt`. putJwt no-ops on null.
43+
jwtTokenStore.putJwt(externalId, jwtBearerToken)
44+
operationRepo.forceExecuteOperations()
4545
return null
4646
}
4747

4848
// Store the JWT before the LoginUserOperation enqueues so that when the op
4949
// dispatches, the JWT lookup in `hasValidJwtIfRequired` already succeeds.
50-
if (jwtBearerToken != null) {
51-
jwtTokenStore.putJwt(externalId, jwtBearerToken)
52-
}
50+
// putJwt no-ops on null.
51+
jwtTokenStore.putJwt(externalId, jwtBearerToken)
5352
userSwitcher.createAndSwitchToNewUser { identityModel, _ ->
5453
identityModel.externalId = externalId
5554
}

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/LoginHelperTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,10 @@ class LoginHelperTests : FunSpec({
331331
if (context != null) loginHelper.enqueueLogin(context)
332332
}
333333

334-
// Then: no user-switch happened, but JWT was refreshed.
334+
// Then: no user-switch happened, JWT was refreshed, and the queue was woken so any
335+
// ops deferred by hasValidJwtIfRequired dispatch immediately.
335336
verify(exactly = 0) { mockUserSwitcher.createAndSwitchToNewUser(suppressBackendOperation = any(), modify = any()) }
336337
jwtTokenStore.getJwt(currentExternalId) shouldBe "new-jwt"
338+
verify(exactly = 1) { mockOperationRepo.forceExecuteOperations() }
337339
}
338340
})

0 commit comments

Comments
 (0)