Skip to content

Call unregisterDeviceToken() on sign-out, but before the user is signed out. #87

@nriedman

Description

@nriedman

Problem

Currently, in the NotificationManager, we unregister the user's device token for push notifications when the user signs out. We do so with the following logic when we receive an AccountNotification:

case .disassociatingAccount:
    do {
        _ = try await self.unregisterDeviceToken()
    } catch {
        self.logger.error("\(error.localizedDescription)")
        self.state = .error(
            AnyLocalizedError(
                error: error,
                defaultErrorDescription: "Unable to unregister for remote notifications."
            )
        )
    }

That is, when we are notified of a disassociating account, we call unregisterDeviceToken(), which then calls a cloud function to unregister the device token from the server. However, by this time, the user is already signed out, and thus is not authenticated. This causes the cloud function call to fail every time, which then causes a disruptive alert.

Solution

Here is a (non-exhaustive) list of a few solutions that might be good to consider:

  • Pass an async closure to AccountOverview (which ultimately contains the logout button) that is then called right before signing the user out in the logout button's action.
  • Modify the mechanism that sends AccountNotifications to send the notifications after the user initiates the logout process (i.e. taps the logout button) but before actually signing out the user.
  • Allow the user to be unauthenticated when calling the unregisterDevice cloud function, and instead authenticate to the best of our abilities by passing the AccountDetails provided by the AccountNotifications (which includes userID) to the cloud function.

Each option has pros and cons -- I'd love to hear what you think and/or any other solutions we should consider @PSchmiedmayer and @Supereg.

Until this is addressed, I've gone ahead and removed the logic that calls unregisterDeviceToken() in the NotificationManager on sign out. Once the issue is fixed, please add the following case to the switch case in NotificationManager.handleAccountNotifications:

case .disassociatingAccount:
    do {
        _ = try await self.unregisterDeviceToken()
    } catch {
        self.logger.error("\(error.localizedDescription)")
        self.state = .error(
            AnyLocalizedError(
                error: error,
                defaultErrorDescription: "Unable to unregister for remote notifications."
            )
        )
    }

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct and Contributing Guidelines

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions