Fix in news, first android notification service
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 7m50s
Code Analysis and Production Deploy / deploy-production (push) Has been skipped
Code Analysis and Production Deploy / deploy-test (push) Has been skipped

This commit is contained in:
Torsten Schulz (local)
2026-06-10 13:47:33 +02:00
parent e8a50e55ca
commit 5da11d2e4d
28 changed files with 1277 additions and 43 deletions

View File

@@ -0,0 +1,24 @@
import { verifyToken, getUserFromToken } from '../../utils/auth.js'
import { notificationSettingsForUser } from '../../utils/notification-settings.js'
function tokenFromEvent(event) {
return getCookie(event, 'auth_token') || getHeader(event, 'authorization')?.replace(/^Bearer\s+/i, '')
}
async function requireAuthenticatedUser(event) {
const token = tokenFromEvent(event)
if (!token) throw createError({ statusCode: 401, message: 'Nicht authentifiziert.' })
const decoded = verifyToken(token)
if (!decoded) throw createError({ statusCode: 401, message: 'Ungültiges Token.' })
const user = await getUserFromToken(token)
if (!user) throw createError({ statusCode: 401, message: 'Ungültige Sitzung.' })
return { token, decoded, user }
}
export default defineEventHandler(async (event) => {
const { user } = await requireAuthenticatedUser(event)
return {
success: true,
settings: notificationSettingsForUser(user)
}
})