Name:
interface
Value:
Extend your Amplify Gen 2 app with AWS Blocks — self-contained backend capabilities you compose into your existing backend.

Remove a device

Use removeDevice to de-register the current device so that Amazon Connect journeys stop delivering notifications to it.

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.

Call removeDevice before signing out. De-registration is signed with the current user's credentials, and your backend removes a device only when the calling identity owns it. After sign-out completes those credentials are gone and the caller signs as a new guest identity, so a removal attempted at that point cannot de-register the signed-in user's device.

Reversing the order leaves the device registered against the signed-out user's profile, and a later journey can deliver their notifications to a device they no longer use.

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:

Future<void> handleSignOut() async {
try {
await client.removeDevice();
} on ConnectClientException catch (e) {
safePrint('Failed to remove device before sign out: $e');
}
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 ConnectClientException subtype when the request cannot complete. When no device has ever been registered on this installation there is nothing to remove, so the call returns without contacting the endpoint.