Skip to main content
POST
/
notifications
/
register-fcm-token
Register FCM Token
curl --request POST \
  --url http://localhost:3000/api/notifications/register-fcm-token \
  --header 'Content-Type: application/json' \
  --data '
{
  "token": "ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]",
  "deviceId": "device_abc123",
  "platform": "ios"
}
'
{
  "success": true,
  "message": "FCM token registered successfully"
}

Overview

Registers a Firebase Cloud Messaging (FCM) token for push notifications on mobile devices. This endpoint should be called when:
  • User logs in on a mobile device
  • App starts and user is already logged in
  • FCM token is refreshed

Use Cases

  • Mobile App Login: Register device for push notifications after successful login
  • App Startup: Re-register token when app starts with authenticated user
  • Token Refresh: Update token if FCM token changes (rare but possible)

Important Notes

Each device needs a unique deviceId. Use a persistent identifier like Device.deviceId in React Native/Expo.
Users can have multiple registered devices (iPhone, iPad, Android tablet). All devices will receive push notifications.

Example Usage

React Native/Expo

import * as Notifications from "expo-notifications";
import * as Device from "expo-device";
import { Platform } from "react-native";

// Request permissions and get token
const { status } = await Notifications.requestPermissionsAsync();
if (status !== "granted") {
  console.log("Permission not granted");
  return;
}

const token = (await Notifications.getExpoPushTokenAsync()).data;

// Register with backend
await fetch("/api/notifications/register-fcm-token", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    token,
    deviceId: Device.deviceId,
    platform: Platform.OS,
  }),
});

See Also

Body

application/json
token
string
required

Firebase Cloud Messaging token from the device

Example:

"ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]"

deviceId
string
required

Unique identifier for the device

Example:

"device_abc123"

platform
enum<string>
required

Platform of the device

Available options:
ios,
android,
web
Example:

"ios"

Response

FCM token registered successfully

success
boolean
required

Whether the operation was successful

Example:

true

message
string
required

Success message

Example:

"FCM token registered successfully"