DEV Community

Cover image for Firebase push Notification Error: ⚠️ Auth error from APNS or Web Push Service
Sarwar Hossain
Sarwar Hossain

Posted on

Firebase push Notification Error: ⚠️ Auth error from APNS or Web Push Service

When Push Notification from Nodejs Express server by firebase -admin.

Your Error::



(node:internal/process/task_queues:95:5) {
errorInfo: {
code: 'messaging/third-party-auth-error',
message: 'Auth error from APNS or Web Push Service'
},
codePrefix: 'messaging'
}

Enter fullscreen mode Exit fullscreen mode




Old Code::




import * as admin from 'firebase-admin';
// import path from 'path';
import ApiError from '../../../errors/ApiError';
import httpStatus from 'http-status';
import config from '../../../config';

admin.initializeApp({
credential: admin.credential.cert(
// path.join(
// __dirname,
// './jornee-66109-firebase-adminsdk-tf0wd-f34c47323d.json',
// ),
firebaseConfig as any,
),
});

type NotificationPayload = {
title: string;
body: string;
data?: { [key: string]: string };
};

export const sendNotification = async (
fcmToken: string,
payload: NotificationPayload,
): Promise<any> => {
// console.log(fcmToken, 'fcmTokenfcmToken');
// console.log(payload, 'payload');
try {
const response = await admin.messaging().send({
token: fcmToken,
notification: {
title: payload.title,
body: payload.body,
},
// data: payload?.data,
});
// console.log('Successfully sent message:', response);
return response;
} catch (error: any) {
console.error('Error sending message:', error);
if (error?.code === 'messaging/third-party-auth-error') {
// console.error('Skipping iOS token due to auth error:', error);
return null;
} else {
console.error('Error sending message:', error);
throw new ApiError(
httpStatus.NOT_IMPLEMENTED,
'Failed to send notification',
);
}
}
};

Enter fullscreen mode Exit fullscreen mode




Solve-1 :

Update your code for multiple users fcmToken.

**

Image description

Get a better response without error::
Image description

Solve-2 :

  1. check your Firebase app settings and create Android and iOS apps.
  2. enable cloud messaging
  3. to provide correct fcmToken
  4. generate fcmToken from the production iOs app.

Top comments (0)