Skip to main content
POST
/
notifications
/
remove-fcm-token
Remove FCM Token
curl --request POST \
  --url http://localhost:3000/api/notifications/remove-fcm-token \
  --header 'Content-Type: application/json' \
  --data '
{
  "deviceId": "device_abc123"
}
'
{
  "success": true,
  "message": "FCM token removed successfully"
}

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

Always call this endpoint during logout to prevent sending notifications to devices where the user is no longer logged in.
Invalid tokens are automatically cleaned up by the system when FCM delivery fails, but manual removal on logout is recommended.

Example Usage

React Native/Expo

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

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

See Also

Body

application/json
deviceId
string
required

Unique identifier for the device to remove

Example:

"device_abc123"

Response

FCM token removed successfully

success
boolean
required

Whether the operation was successful

Example:

true

message
string
required

Success message

Example:

"FCM token removed successfully"