Remove a device
Use removeDevice to de-register the current device so that Amazon Connect journeys stop delivering notifications to it.
try await client.removeDevice()removeDevice takes no arguments. The library resolves the device identifier for you, and your backend permits removal only of a device that the calling identity owns.
Sign a user out safely
Handle a failed removal deliberately rather than letting it block sign-out. The following pattern signs the user out even when de-registration fails, which avoids trapping a user in a signed-in state because of a network error:
func handleSignOut() async { do { try await client.removeDevice() } catch { print("Failed to remove device before sign out: \(error)") }
_ = await Amplify.Auth.signOut()}When to call removeDevice
Call removeDevice in these situations:
- Before signing a user out, as described above.
- When a user turns off notifications in your application's settings.
- Before deleting a user's account.
You do not need to call removeDevice when the push token is replaced. Registration is keyed on a device identifier that is stable for the installation, so registering with a new token updates the existing record. See Register a device.
Register the device again
The device identifier persists after removal, so a user who opts back in can be registered again with registerDevice. Removing a device does not reset the identifier or require your application to store one.
Handle errors
removeDevice throws a ConnectError when the request cannot complete, and throws ConnectError.validation when no device has ever been registered on this installation, because there is no registration to remove.