Xeovalyte
388d989229
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
20 lines
570 B
JavaScript
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 })
|
|
}
|
|
})
|