# Register Device Token

Register a Firebase Cloud Messaging (FCM) token so the user's device receives Aurea's push notifications.

## Overview

Aurea sends push notifications through **Firebase Cloud Messaging** — for example when a bank ramp deposit arrives or a payout completes. After the user signs in, get the device's FCM token from the Firebase SDK and register it here, together with the platform.

Tokens are stored per token: registering a token that is already stored updates that record instead of adding a duplicate, so it is safe to call this on every app start or whenever Firebase issues a new token.

## Endpoint

### `POST /v1/notifications/device-token`

Authentication: bearer token required.

Registers (or updates) an FCM device token for the authenticated user.

**Request body**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `fcmToken` | string | yes | Firebase Cloud Messaging token from the Firebase SDK |
| `platform` | string | yes | ios \| android \| web |

**Responses**

`201` Created

```json
{ "success": true, "message": "Device token registered successfully" }
```

## Implementation

```javascript
import { getMessaging, getToken } from 'firebase/messaging';

async function registerForPush(accessToken) {
  if (await Notification.requestPermission() !== 'granted') return;

  const fcmToken = await getToken(getMessaging(), { vapidKey: 'YOUR_VAPID_KEY' });

  const res = await fetch('https://api.aureahub.com/v1/notifications/device-token', {
    method: 'POST',
    headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ fcmToken, platform: 'web' })
  });
  if (!res.ok) throw new Error(`Token registration failed: ${res.status}`);
  return fcmToken; // keep it to unregister on sign-out
}
```

---

Web version: https://docs.aureahub.com/#notif-register
