@quintype/framework 7.33.6-fcm-fix-1.1 → 7.33.6-fcm-fix-1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.33.6-fcm-fix-1.1",
3
+ "version": "7.33.6-fcm-fix-1.3",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -29,33 +29,26 @@ exports.registerFCMTopic = async function registerFCM (
29
29
  })
30
30
 
31
31
  console.log('admin------', admin)
32
- async function generateAccessToken () {
33
- const token = await admin.credential.cert(fcmServiceAccountJson).getAccessToken()
34
- console.log('OAuth2 Access Token:', token)
35
- return token
36
- }
37
-
38
- const oauthToken = generateAccessToken()
39
-
40
- if (!oauthToken) {
41
- res.status(500).send('Oauth Token is not available')
42
- return
43
- }
44
-
45
- const url = `https://iid.googleapis.com/iid/v1/${token}/rel/topics/all`
46
- try {
47
- await request({
48
- uri: url,
49
- method: 'POST',
50
- headers: {
51
- Authorization: `Bearer ${oauthToken}`,
52
- 'content-type': 'application/json'
32
+ const oauthToken = await admin.credential
33
+ .cert(serviceAccount)
34
+ .getAccessToken()
35
+ .then(tokenObj => {
36
+ console.log('OAuth2 Access Token:', tokenObj)
37
+ if (tokenObj && tokenObj.access_token) {
38
+ return tokenObj.access_token
53
39
  }
54
40
  })
55
- res.status(200).send('Registration Done Suceessfuly')
56
- return
57
- } catch (error) {
58
- res.status(500).send('FCM Subscription Failed', error)
59
- return
60
- }
41
+ .catch(error => res.status(400).send(`Oauth Token is not available: ${error}`))
42
+
43
+ const url = `https://iid.googleapis.com/iid/v1/${token}/rel/topics/all`
44
+ await request({
45
+ uri: url,
46
+ method: 'POST',
47
+ headers: {
48
+ Authorization: `Bearer ${oauthToken}`,
49
+ 'content-type': 'application/json'
50
+ }
51
+ })
52
+ .then(() => res.status(200).send('Registration Done Successfully'))
53
+ .catch(error => res.status(500).send(`FCM Subscription Failed: ${error}`))
61
54
  }