@quintype/framework 7.33.6-fcm-fix-1.2 → 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
|
@@ -29,33 +29,26 @@ exports.registerFCMTopic = async function registerFCM (
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
console.log('admin------', admin)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
}
|