Admin settings fixed
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* @ai-context Checks if authenticated user is an admin and enforces access control
|
||||
*/
|
||||
|
||||
import { FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify';
|
||||
import { FastifyPluginAsync, FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
|
||||
import fp from 'fastify-plugin';
|
||||
import { Pool } from 'pg';
|
||||
import { logger } from '../logging/logger';
|
||||
@@ -23,8 +23,21 @@ export function setAdminGuardPool(pool: Pool): void {
|
||||
|
||||
const adminGuardPlugin: FastifyPluginAsync = async (fastify) => {
|
||||
// Decorate with requireAdmin function that enforces admin authorization
|
||||
fastify.decorate('requireAdmin', async function(request: FastifyRequest, reply: FastifyReply) {
|
||||
fastify.decorate('requireAdmin', async function(this: FastifyInstance, request: FastifyRequest, reply: FastifyReply) {
|
||||
try {
|
||||
if (typeof this.authenticate !== 'function') {
|
||||
logger.error('Admin guard: authenticate handler missing');
|
||||
return reply.code(500).send({
|
||||
error: 'Internal server error',
|
||||
message: 'Authentication handler missing'
|
||||
});
|
||||
}
|
||||
|
||||
await this.authenticate(request, reply);
|
||||
if (reply.sent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure user is authenticated first
|
||||
if (!request.userContext?.userId) {
|
||||
logger.warn('Admin guard: user context missing');
|
||||
|
||||
Reference in New Issue
Block a user