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

Choose your framework/language

Gen1 DocsLegacy

Page updated Jul 30, 2026

Remove a device

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

import { removeDevice } from 'aws-amplify/push-notifications/customer-profiles';
await 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 signOut. De-registration is signed with the current user's credentials, and your backend removes a device only when the calling identity owns it. After signOut 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. Always await removeDevice first:

import { signOut } from 'aws-amplify/auth';
import { removeDevice } from 'aws-amplify/push-notifications/customer-profiles';
await removeDevice();
await signOut();

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:

import { signOut } from 'aws-amplify/auth';
import { removeDevice } from 'aws-amplify/push-notifications/customer-profiles';
const handleSignOut = async () => {
try {
await removeDevice();
} catch (error) {
console.error('Failed to remove device before sign out', error);
}
await 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 rejects in the following cases:

  • Push notifications are not initialized. Call initializePushNotifications before removing a device.
  • The request failed. The endpoint returned a non-success status, or the request could not complete.