wrbapp/frontend/server/api/subscribetotopic.post.js
Xeovalyte 388d989229
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fixed firebase admin error
2023-01-22 17:37:10 +01:00

20 lines
570 B
JavaScript

import { messaging } from '../utils/firebase'
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 messaging.subscribeToTopic([registrationToken], topic)
return { code: 'success'}
} catch (e) {
console.log(e)
throw createError({ statusCode: 500, statusMessage: e.message })
}
})