Hi,
I’m trying to use Firebase Cloud Messaging with NODE and EJS. I’m using the code from the documentation to receive an access token, from :
https://firebase.google.com/docs/cloud-messaging/auth-server
Here’s the code:
function getAccessToken() {
return new Promise(function(resolve, reject) {
var key = require('./service-account.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}
I’ve made a NODE module “tokens.js” which is served to my Index.ejs, but I get this error “SCOPES is not defined” - here’s the full error:
Marks-MacBook-Pro:Firebase_EJS_TEST markokoh$ node app.js
Example app listening on port 3030!
(node:1790) UnhandledPromiseRejectionWarning: ReferenceError: SCOPES is not defined
at /Users/markokoh/NODE_EXPERESS_EXAMPLES/Firebase_EJS_TEST/tokens.js:28:7
at new Promise (<anonymous>)
at Object.getAccessToken [as testTokens] (/Users/markokoh/NODE_EXPERESS_EXAMPLES/Firebase_EJS_TEST/tokens.js:22:10)
at /Users/markokoh/NODE_EXPERESS_EXAMPLES/Firebase_EJS_TEST/app.js:24:25
at Layer.handle [as handle_request] (/Users/markokoh/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/markokoh/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/markokoh/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/markokoh/node_modules/express/lib/router/layer.js:95:5)
at /Users/markokoh/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/markokoh/node_modules/express/lib/router/index.js:335:12)
(node:1790) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1790) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Any ideas how to fix it?
Thanks