firebase / firebase/quickstart-js

[Firebase Cloud Messaging Quickstart] Should be updated to use Firebase Cloud Messaging API (V1)

Open
#700 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
3.7k
Avg merge
2d 13h
Merged PRs (30d)
6

Description

### Step 1: Describe your environment

* Operating system: maxOS Ventura
* Browser: Chrome
* Firebase SDK version: 9.18.0

### Step 2: Describe the problem:

As Firebase Cloud Messaging API (V1) is now enabled by default, the tutorial does not work anymore out of the box with the new API as there won't be a server key to use. You can still follow the tutorial though if you enable the Cloud Messaging API (Legacy) but this would need to be documented.

#### Steps to reproduce:

1. Follow the tutorial in `[quickstart-js/messaging](https://github.com/firebase/quickstart-js/messaging/)`
2. See the curl request will throw the error `INVALID_KEY` or `PROJECT_NOT_PERMITTED`

#### Observed Results:

Running the proposed command:
```
curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1",
"icon": "firebase-logo.png",
"click_action": "http://localhost:8081"
},
"to": "YOUR-IID-TOKEN"
}' "https://fcm.googleapis.com/fcm/send"
```
will throw the error `INVALID_KEY` or `PROJECT_NOT_PERMITTED`

#### Expected Results:

Have 2 messaging examples. One working with `Cloud Messaging API (Legacy)` and the other working with `Firebase Cloud Messaging API (V1)`. Provide enough relevant information to make the examples work out of the box.

#### Relevant Code:

Follow the instructions in `[quickstart-js/messaging](https://github.com/firebase/quickstart-js/messaging/)` with a new Firebase project.

Run:
```
curl -X POST -H "Authorization: key=YOUR-SERVER-KEY" -H "Content-Type: application/json" -d '{
"notification": {
"title": "Portugal vs. Denmark",
"body": "5 to 1",
"icon": "firebase-logo.png",
"click_action": "http://localhost:8081"
},
"to": "YOUR-IID-TOKEN"
}' "https://fcm.googleapis.com/fcm/send"
```
See it returns `INVALID_KEY` or `PROJECT_NOT_PERMITTED`.

If anyone else comes across this issue: This medium article helped me making `Firebase Cloud Messaging API (V1)` work: https://apoorv487.medium.com/testing-fcm-push-notification-http-v1-through-oauth-2-0-playground-postman-terminal-part-2-7d7a6a0e2fa0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.