Skip to content

Commit 130aa16

Browse files
committed
Skip push subscription disable on logout when JWT is already expired
When IV is enabled and the JWT has already been invalidated (e.g. by a prior 401), the UpdateSubscriptionOperation to disable the push subscription would be permanently blocked by hasValidJwtIfRequired. Since the backend call would fail with 401 anyway, skip it entirely and just switch to the new anonymous user. Made-with: Cursor Revert "Skip push subscription disable on logout when JWT is already expired" This reverts commit 5ce284257b6e03b8c862745ff58fcf4293299577. Exempt UpdateSubscriptionOperation from JWT gating The subscription update endpoint does not require a JWT on the backend. Add Operation.requiresJwt (default true) and override it to false in UpdateSubscriptionOperation so these operations are not blocked by hasValidJwtIfRequired when the JWT is expired or missing. This fixes the edge case where logging out with an expired JWT would permanently block the push subscription disable operation. Made-with: Cursor
1 parent 76dd958 commit 130aa16

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/Operation.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ abstract class Operation(name: String) : Model() {
6161
*/
6262
abstract val canStartExecute: Boolean
6363

64+
/**
65+
* Whether this operation requires a valid JWT when identity verification is enabled.
66+
* Override to return `false` for operations whose backend endpoint does not require
67+
* a JWT (e.g. subscription updates).
68+
*/
69+
open val requiresJwt: Boolean get() = true
70+
6471
/**
6572
* Called when an operation has resolved a local ID to a backend ID (i.e. successfully
6673
* created a backend resource). Any IDs within the operation that could be local IDs should

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ internal class OperationRepo(
438438
op: Operation,
439439
): Boolean {
440440
if (!iv) return true
441+
if (!op.requiresJwt) return true
441442
val externalId = op.externalId ?: return false
442443
return _jwtTokenStore.getJwt(externalId) != null
443444
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class UpdateSubscriptionOperation() : Operation(SubscriptionOperationExecutor.UP
8686
override val groupComparisonType: GroupComparisonType = GroupComparisonType.ALTER
8787
override val canStartExecute: Boolean get() = !IDManager.isLocalId(onesignalId) && !IDManager.isLocalId(subscriptionId)
8888
override val applyToRecordId: String get() = subscriptionId
89+
override val requiresJwt: Boolean get() = false
8990

9091
constructor(appId: String, onesignalId: String, subscriptionId: String, type: SubscriptionType, enabled: Boolean, address: String, status: SubscriptionStatus) : this() {
9192
this.appId = appId

0 commit comments

Comments
 (0)