diff --git a/backend/index.js b/backend/index.js index 03c1c07..09ae64f 100644 --- a/backend/index.js +++ b/backend/index.js @@ -2,6 +2,7 @@ const express = require('express'); const cors = require('cors'); const { initializeApp, applicationDefault, cert } = require('firebase-admin/app'); const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore'); +const { getMessaging } = require('firebase-admin/messaging') const { verifyIdToken } = require('firebase-admin/auth') const serviceAccount = require('./firebase.json'); @@ -80,6 +81,31 @@ app.post('/getrelatiecodes', async (req, res) => { res.status(200).send({ code: 'success', relatiecodes: relatiecodes, persons: persons }) + } catch (e) { + return res.status(500).send({ code: 'error', error: e }) + } +}) + +app.post('/subscribetotopic', async (req, res) => { + const { topic, registrationToken } = req.body; + + if (!topic) return res.status(400).send({ code: 'no-topic'}) + if (!registrationToken) return res.status(400).send({ code: 'no-registrationToken'}) + + try { + getMessaging().subscribeToTopic([registrationToken], topic) + .then((response) => { + console.log('Successfully subscribed to topic:', response); + + res.status(200).send({ code: 'success' }) + }) + .catch((error) => { + console.log('Error subscribing to topic:', error); + + return res.status(500).send({ code: 'error', error: e }) + }); + + } catch (e) { return res.status(500).send({ code: 'error', error: e }) } diff --git a/frontend/app.vue b/frontend/app.vue index 2dd7d6a..e87a32b 100644 --- a/frontend/app.vue +++ b/frontend/app.vue @@ -18,6 +18,7 @@