wrbapp/frontend/server/api/subscribetotopic.post.js

20 lines
570 B
JavaScript
Raw Normal View History

2023-01-22 17:37:10 +01:00
import { messaging } from '../utils/firebase'
2023-01-21 21:36:22 +01:00
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 {
2023-01-22 17:37:10 +01:00
await messaging.subscribeToTopic([registrationToken], topic)
2023-01-21 21:36:22 +01:00
return { code: 'success'}
} catch (e) {
console.log(e)
throw createError({ statusCode: 500, statusMessage: e.message })
}
})