> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Device Registration

> Verify new devices and manage trusted devices for your users.

Device registration protects your users from account takeovers by requiring verification when they sign in from an unrecognized device. For a general overview of the feature, see [Device Registration](/overview/security/device-registration).

## Prerequisites

* You need to have the Dynamic Client initialized.
* You need to have device registration enabled in your environment's settings in the [Dynamic Dashboard](https://app.dynamic.xyz).
* JavaScript SDK v2 or later.

## Checking if device registration is required

After a user authenticates, check whether their current device needs to be registered. This is determined by the `device:register` scope in the user's session.

```javascript theme={"system"}
import { isDeviceRegistrationRequired } from '@dynamic-labs-sdk/client';

const user = dynamicClient.user;

if (user && isDeviceRegistrationRequired(user)) {
  // Show a banner or prompt to the user
  // The user will receive an email with a verification link
}
```

## Completing device registration

When the user clicks the verification link in their email, they are redirected back to your app with a token in the URL. You need to detect this redirect and complete the registration.

```javascript theme={"system"}
import {
  detectDeviceRegistrationRedirect,
  getDeviceRegistrationTokenFromUrl,
  completeDeviceRegistration,
} from '@dynamic-labs-sdk/client';

const url = window.location.href;

if (detectDeviceRegistrationRedirect({ url })) {
  const deviceToken = getDeviceRegistrationTokenFromUrl({ url });
  const response = await completeDeviceRegistration({ deviceToken });

  // Device is now trusted — the user has full access
  console.log('Device registered for user:', response.user);
}
```

## Listening for events

You can listen for device registration events to update your UI accordingly.

```javascript theme={"system"}
import { onEvent } from '@dynamic-labs-sdk/client';

// Fires when registration completes in the current tab
onEvent({
  event: 'deviceRegistrationCompleted',
  listener: () => {
    // Hide the registration banner, update UI, etc.
  },
});

// Fires when registration completes in another tab
onEvent({
  event: 'deviceRegistrationCompletedInAnotherTab',
  listener: () => {
    // Keep other open tabs in sync
  },
});
```

## Getting registered devices

Retrieve all trusted devices for the current user.

```javascript theme={"system"}
import { getRegisteredDevices } from '@dynamic-labs-sdk/client';

const devices = await getRegisteredDevices();

devices.forEach((device) => {
  console.log(device.id, device.userAgent, device.isCurrentDevice);
});
```

Each device includes:

| Field             | Type      | Description                                   |
| ----------------- | --------- | --------------------------------------------- |
| `id`              | `string`  | The device registration ID                    |
| `createdAt`       | `string`  | ISO date of when the device was registered    |
| `userAgent`       | `string`  | The browser or device user agent              |
| `isCurrentDevice` | `boolean` | Whether this is the device making the request |

### Displaying devices

You can use `parseUserAgent` to display a friendly device name from the raw user agent string.

```tsx theme={"system"}
import { parseUserAgent } from '@dynamic-labs-sdk/client';
import { useGetRegisteredDevices } from '@dynamic-labs-sdk/react-hooks';

function RegisteredDevices() {
  const { data: devices = [] } = useGetRegisteredDevices();

  return (
    <ul>
      {devices.map((device) => {
        const parsed = parseUserAgent({ userAgent: device.userAgent });

        return (
          <li key={device.id}>
            {parsed?.type === 'mobile' ? '📱' : '💻'}{' '}
            {parsed?.displayText ?? 'Unknown device'}
            {device.isCurrentDevice && ' (this device)'}
          </li>
        );
      })}
    </ul>
  );
}
```

## Revoking a device

Remove a single trusted device. If the revoked device is the current device, the user will be logged out.

```javascript theme={"system"}
import { revokeRegisteredDevice } from '@dynamic-labs-sdk/client';

await revokeRegisteredDevice({ deviceRegistrationId: 'device-id' });
```

## Revoking all devices

Remove all trusted devices for the current user. This always logs the user out.

```javascript theme={"system"}
import { revokeAllRegisteredDevices } from '@dynamic-labs-sdk/client';

await revokeAllRegisteredDevices();
```

## Related

* [Device Registration Overview](/overview/security/device-registration) — How device registration works and why it matters
* [Security Overview](/overview/security/overview) — Dynamic's security posture
