The "messaging/mismatched-sender-id" error occurs when the Firebase Cloud Messaging (FCM) Sender ID used by your client app does not match the Sender ID associated with the Firebase project you are using to send messages. This typically happens when registration tokens were generated from a different Firebase project than the one your server is using to send push notifications.
The "messaging/mismatched-sender-id" error indicates that the Firebase Cloud Messaging registration token on the client was generated from a Firebase project that is different from the Firebase project credentials being used on your server to send the push notification. The Sender ID identifies your app to Firebase Cloud Messaging when it requests a registration token. If the client app and server credentials belong to different Firebase projects, the server cannot send messages to tokens generated by the client, resulting in this error.
Find your Sender ID in the Firebase Console:
1. Go to [Firebase Console](https://console.firebase.google.com)
2. Select your project
3. Navigate to Project Settings (gear icon) > Cloud Messaging tab
4. Your Sender ID is displayed prominently (it's the same as your Project Number)
5. Note this Sender ID for comparison with your client configuration
You'll need this to verify your client app is using the correct project.
Ensure your client app is initialized with the correct Firebase project:
Web/JavaScript (using SDK):
import { initializeApp } from "firebase/app";
import { getMessaging, getToken } from "firebase/messaging";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
projectId: "YOUR_PROJECT_ID", // This must match your server project
messagingSenderId: "YOUR_SENDER_ID", // Verify this matches Firebase Console
appId: "YOUR_APP_ID",
};
const app = initializeApp(firebaseConfig);
const messaging = getMessaging(app);
getToken(messaging, {
vapidKey: "YOUR_VAPID_KEY"
}).then(token => {
console.log("Registration token:", token);
});Android (Firebase config):
<!-- Check your google-services.json file contains the correct project ID -->
<!-- The Sender ID in google-services.json must match your Firebase project -->Verify the projectId and messagingSenderId match your Firebase Console settings.
Ensure your backend server uses credentials from the same Firebase project:
Node.js Admin SDK:
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
// Note: Do NOT override the project ID. Admin SDK uses the project ID
// from your service account JSON file. This MUST match your client project.
});
// Verify the project ID
console.log("Server using project:", admin.app().options.projectId);
// Send a message
admin.messaging().sendToDevice(registrationToken, message)
.catch(error => {
if (error.code === "messaging/mismatched-sender-id") {
console.log("Client and server using different Firebase projects!");
}
});Verification: The project_id in your serviceAccountKey.json must match the project ID shown in your client's Firebase config.
If you've corrected your Firebase configuration, you need to generate new registration tokens:
Web/JavaScript:
import { getMessaging, getToken, deleteToken } from "firebase/messaging";
const messaging = getMessaging();
// Delete old token (optional, forces new token generation)
await deleteToken(messaging);
// Request new token with fresh configuration
const token = await getToken(messaging, {
vapidKey: "YOUR_VAPID_KEY"
});
console.log("New registration token:", token);
// Send this new token to your server to replace the old one
await fetch("/api/update-token", {
method: "POST",
body: JSON.stringify({ token })
});Android:
import com.google.firebase.messaging.FirebaseMessaging;
// Firebase automatically generates a new token when re-initialized
// with correct google-services.json
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(task -> {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
String token = task.getResult();
Log.d(TAG, "New FCM Token: " + token);
});Store this new token on your server, replacing the old mismatched token.
Verify that messages now send successfully:
Node.js test:
const admin = require("firebase-admin");
const message = {
notification: {
title: "Test Notification",
body: "If you see this, sender ID is now matched!"
},
token: newRegistrationToken // Use the newly generated token
};
admin.messaging().send(message)
.then(response => {
console.log("Message sent successfully:", response);
})
.catch(error => {
if (error.code === "messaging/mismatched-sender-id") {
console.log("Still mismatched! Check configuration again.");
} else {
console.log("Error sending message:", error);
}
});If the message sends successfully (no error), your Sender ID mismatch is resolved.
If you're migrating from Google Cloud Messaging (GCM) to Firebase Cloud Messaging:
1. Identify old vs new tokens: Old GCM tokens belong to your previous GCM project; new FCM tokens belong to your new FCM project
2. Sender ID difference: GCM and FCM projects have different Sender IDs, which causes mismatches
3. Migration strategy:
- Keep track of which tokens are from the old GCM project and which are from new FCM
- Send GCM messages using old credentials (if still supporting GCM)
- Send FCM messages only to new FCM tokens
- Encourage users to update their apps to generate new FCM tokens
4. Deprecate old tokens: Over time, transition all users to the new Firebase project
Consider keeping both GCM and FCM endpoints active during transition period.
The Sender ID is derived from your Firebase project number and is distinct from the Project IDβthey are different values. When using Pub/Sub based messaging flows, ensure your subscription credentials also use the same Firebase project. If you're using third-party notification services (like Batch, Airship, or Pushwoosh), verify their Firebase integration is connected to the correct project. In development environments using Firebase Emulator, ensure both client and emulator are configured with the same project ID. The error message may also appear as "SenderId mismatch" or "mismatched-sender-id" depending on your SDK version.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
Hosting: CORS configuration not set up properly
How to fix CORS configuration in Firebase Hosting
auth/reserved-claims: Custom claims use reserved OIDC claim names
How to fix "reserved claims" error when setting custom claims in Firebase
Callable Functions: UNAUTHENTICATED - Invalid credentials
How to fix "UNAUTHENTICATED - Invalid credentials" in Firebase Callable Functions