17 lines
512 B
TypeScript
17 lines
512 B
TypeScript
import { requireAuth } from '~/server/utils/auth'
|
|
import { pushSubscriptions } from '~/server/utils/db'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = requireAuth(event)
|
|
const body = await readBody(event)
|
|
const { subscription } = body
|
|
|
|
if (!subscription?.endpoint) {
|
|
throw createError({ statusCode: 400, message: 'Invalid subscription' })
|
|
}
|
|
|
|
pushSubscriptions.set(user.id, { userId: user.id, subscription, createdAt: new Date().toISOString() })
|
|
|
|
return { success: true }
|
|
})
|