Firebase Error: Auth error from APNS or Web Push Service

Did you call admin.initializeApp()?

There are many official samples.

See:

  • https://github.com/firebase/functions-samples/blob/master/fcm-notifications/functions/index.js#L20
  • https://github.com/firebase/functions-samples/tree/master/fcm-notifications
  • https://github.com/firebase/functions-samples
  • https://github.com/firebase/quickstart-js/tree/master/messaging

Everything worked for me the other day, so all setup was fine. But today I got this error.

Here's what solved it for me:

  1. Revoked APNs Key
  2. Created new one and downloaded it
  3. Deleted old one and Uploaded it to Firebase Dashboard / Settings / Cloud Messaging
  4. Gone to Settings / Service Accounts and generated new private key
  5. Added it to my Cloud Functions project (renamed it to service-account.json in my case)
  6. Saved the files and deployed the functions: firebase deploy --only functions

This error arises if your app setup for iOS has an error in any one of the following:

Found in Settings > General > Your Apps > iOS Apps:

  • App Store ID
  • Bundle ID
  • Team ID

enter image description here

When adding an APNs key (Uploading to Cloud Messaging > APNs Authentication Key):

  • Team ID (should auto set based off ios app info above)
  • Key Id (often is in the name of the key, best to grab when creating it)

enter image description here