wrbapp/frontend/server/api/subscribetotopic.post.js
Xeovalyte 587ca2701d
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
reworked backend
2023-01-21 21:36:22 +01:00

20 lines
585 B
JavaScript

import { getMessaging } from 'firebase-admin/messaging'
export default defineEventHandler(async event => {
const { topic, registrationToken } = await readBody(event);
if (!topic) throw createError({ statusCode: 400, statusMessage: 'no-topic'})
if (!registrationToken) throw createError({ statusCode: 400, statusMessage: 'no-registrationtoken'})
try {
await getMessaging().subscribeToTopic([registrationToken], topic)
return { code: 'success'}
} catch (e) {
console.log(e)
throw createError({ statusCode: 500, statusMessage: e.message })
}
})