feat(admin): archive users and their profiles permanently
All checks were successful
Build and Release FEDEO / verify (push) Successful in 1m5s
Build and Release FEDEO / build-and-release (push) Successful in 6m53s

This commit is contained in:
2026-10-15 14:22:12 +02:00
parent 5dc9e686fc
commit 4ffafef3f1
26 changed files with 519 additions and 75 deletions

View File

@@ -12,7 +12,7 @@ import {
tenants,
} from "../../db/schema"
import { eq, and, inArray } from "drizzle-orm"
import { eq, and, inArray, isNull } from "drizzle-orm"
export default fp(async (server: FastifyInstance) => {
const hashApiKey = (apiKey: string) =>
@@ -56,7 +56,8 @@ export default fp(async (server: FastifyInstance) => {
.innerJoin(authUsers, eq(authUsers.id, m2mApiKeys.userId))
.where(and(
eq(m2mApiKeys.keyHash, keyHash),
eq(m2mApiKeys.active, true)
eq(m2mApiKeys.active, true),
isNull(authUsers.archived_at)
))
.limit(1)
@@ -141,22 +142,16 @@ export default fp(async (server: FastifyInstance) => {
return reply.code(401).send({ error: "Invalid token" })
}
// Payload an Request hängen
req.user = payload
if (typeof payload.is_admin === "boolean") {
req.user.is_admin = payload.is_admin
} else {
const [currentUser] = await server.db
.select({
is_admin: authUsers.is_admin,
})
.from(authUsers)
.where(eq(authUsers.id, payload.user_id))
.limit(1)
req.user.is_admin = Boolean(currentUser?.is_admin)
// Check current account state even when a JWT carries cached admin claims.
const [currentUser] = await server.db
.select({ is_admin: authUsers.is_admin })
.from(authUsers)
.where(and(eq(authUsers.id, payload.user_id), isNull(authUsers.archived_at)))
.limit(1)
if (!currentUser) {
return reply.code(401).send({ error: "Invalid or expired token" })
}
req.user = { ...payload, is_admin: Boolean(currentUser.is_admin) }
// Multi-Tenant Modus ohne ausgewählten Tenant → keine Rollenprüfung
if (!req.user.tenant_id) {