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

# Remove FCM Token

> Removes a Firebase Cloud Messaging (FCM) token from the user's registered devices. Call this when user logs out or disables notifications.

## Overview

Removes a Firebase Cloud Messaging (FCM) token from the user's registered devices. This endpoint should be called when:

* User logs out
* User disables push notifications
* App is uninstalled (if possible to detect)

## Use Cases

* **User Logout**: Remove device token to stop receiving notifications
* **Disable Notifications**: User opts out of push notifications in settings
* **Device Cleanup**: Remove old/unused device registrations

## Important Notes

<Warning>
  Always call this endpoint during logout to prevent sending notifications to devices where the user is no longer logged in.
</Warning>

<Info>
  Invalid tokens are automatically cleaned up by the system when FCM delivery fails, but manual removal on logout is recommended.
</Info>

## Example Usage

### React Native/Expo

```typescript theme={null}
import * as Device from "expo-device";

// On logout
async function handleLogout() {
  // Remove FCM token
  await fetch("/api/notifications/remove-fcm-token", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      deviceId: Device.deviceId,
    }),
  });

  // Continue with logout...
}
```

### Using React Hook

```typescript theme={null}
import { useRemoveFCMToken } from '@/hooks/notifications/useFCMTokenRegistration';

function LogoutButton() {
  const { mutate: removeToken } = useRemoveFCMToken();

  const handleLogout = () => {
    removeToken(Device.deviceId, {
      onSuccess: () => {
        console.log('Token removed successfully');
        // Continue with logout
      },
    });
  };

  return <Button onPress={handleLogout}>Logout</Button>;
}
```

## Behavior

When a token is removed:

1. Device token is deleted from user's `fcmTokens` map in Firestore
2. Device will no longer receive push notifications
3. Other registered devices remain active and continue receiving notifications
4. Operation is idempotent - safe to call multiple times

## Related Endpoints

* [Register FCM Token](/engineering/apis/notifications/register-fcm-token) - Register device for notifications
* [Update FCM Token Usage](/engineering/apis/notifications/update-fcm-token-usage) - Track active devices

## See Also

* [FCM Push Notifications Guide](/engineering/notifications/fcm-push-notifications) - Complete implementation guide
* [Token Lifecycle Documentation](/engineering/notifications/fcm-architecture-diagram) - Token management best practices


## OpenAPI

````yaml POST /notifications/remove-fcm-token
openapi: 3.1.0
info:
  title: Tatu API
  description: API documentation for Tatu's booking and artist management system
  version: 1.0.0
servers:
  - url: http://localhost:3000/api
    description: Development server
security: []
paths:
  /notifications/remove-fcm-token:
    post:
      summary: Remove FCM Token
      description: >-
        Removes a Firebase Cloud Messaging (FCM) token from the user's
        registered devices. Call this when user logs out or disables
        notifications.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RemoveFCMTokenRequest'
      responses:
        '200':
          description: FCM token removed successfully
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - message
                properties:
                  success:
                    type: boolean
                    description: Whether the operation was successful
                    example: true
                  message:
                    type: string
                    description: Success message
                    example: FCM token removed successfully
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '405':
          description: Method not allowed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    RemoveFCMTokenRequest:
      type: object
      required:
        - deviceId
      properties:
        deviceId:
          type: string
          description: Unique identifier for the device to remove
          example: device_abc123
    Error:
      type: object
      required:
        - message
      properties:
        message:
          type: string

````