Bugfixing
Some checks failed
Code Analysis and Production Deploy / analyze (push) Failing after 6m10s
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-23 16:21:53 +02:00
parent b69130c2b2
commit f29e8a4dac
10 changed files with 225 additions and 57 deletions

View File

@@ -399,6 +399,42 @@ export async function getUserFromToken(token) {
return user
}
export function getTokenFromEvent(event) {
return getCookie(event, 'auth_token') || getHeader(event, 'authorization')?.replace(/^Bearer\s+/i, '')
}
export async function requireAuthenticatedUser(event) {
const token = getTokenFromEvent(event)
if (!token) {
throw createError({
statusCode: 401,
statusMessage: 'Nicht authentifiziert'
})
}
const user = await getUserFromToken(token)
if (!user) {
throw createError({
statusCode: 401,
statusMessage: 'Ungültige Sitzung'
})
}
return user
}
export async function requireUserWithAnyRole(event, ...roles) {
const user = await requireAuthenticatedUser(event)
if (!hasAnyRole(user, ...roles)) {
throw createError({
statusCode: 403,
statusMessage: 'Zugriff verweigert'
})
}
return user
}
// Create session
export async function createSession(userId, token) {
const sessions = await readSessions()