I've been building an app on RN and static stuff are working as intended. Now I'm trying to add Push Notifications and all tries lead me to this error: You must provide 'notification.vapidPublicKey' in 'app.json' to use push notifications on web..
There are several tutorials around and they all seems so simple and none of them have this error...
So, I've tried 5+ tutorials, using Node 14, react-native-web 0.11.7 (due async issues), including owner, slug and notification.vapidPublicKey on app.json (the last one is not accepted by the file), and a lot of other stuffs, like trying to have this working on a brand new project.
This error occours when I call await Notifications.getExpoPushTokenAsync() from import { Notifications } from 'expo';.
"dependencies": {
"@expo-google-fonts/inter": "^0.1.0",
"expo": "~37.0.3",
"moment": "^2.27.0",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-screens": "~2.2.0",
"react-native-web": "0.11.7"
},
"devDependencies": {
"@babel/core": "^7.8.6",
"@types/react": "~16.9.23",
"@types/react-native": "~0.61.17",
"babel-preset-expo": "~8.1.0",
"styled-components": "^5.1.1",
"typescript": "~3.8.3"
},
Any ideas on how to fix this error?
In order to use push notifications in a web application, you need to provide the vapidPublicKey in the app.json file.
The vapidPublicKey is a string that represents the public key of your VAPID (Voluntary Application Server Identification) key pair. This key pair is used to identify your server when sending push notifications to web clients.
To generate a VAPID key pair, you can use the web-push library. Here's an example of how to generate a key pair and add it to your app.json file:
Install the web-push library:
npm install --save web-push