Admin User v1

This commit is contained in:
Eric Gullickson
2025-11-05 19:04:06 -06:00
parent e4e7e32a4f
commit 8174e0d5f9
48 changed files with 11289 additions and 1112 deletions

View File

@@ -15,6 +15,12 @@ declare module 'fastify' {
interface FastifyRequest {
jwtVerify(): Promise<void>;
user?: any;
userContext?: {
userId: string;
email?: string;
isAdmin: boolean;
adminRecord?: any;
};
}
}
@@ -68,9 +74,17 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
fastify.decorate('authenticate', async function(request: FastifyRequest, reply: FastifyReply) {
try {
await request.jwtVerify();
// Hydrate userContext with basic auth info
const userId = request.user?.sub;
request.userContext = {
userId,
email: request.user?.email,
isAdmin: false, // Default to false; admin status checked by admin guard
};
logger.info('JWT authentication successful', {
userId: request.user?.sub?.substring(0, 8) + '...',
userId: userId?.substring(0, 8) + '...',
audience: auth0Config.audience
});
} catch (error) {
@@ -79,10 +93,10 @@ const authPlugin: FastifyPluginAsync = async (fastify) => {
method: request.method,
error: error instanceof Error ? error.message : 'Unknown error',
});
reply.code(401).send({
error: 'Unauthorized',
message: 'Invalid or missing JWT token'
reply.code(401).send({
error: 'Unauthorized',
message: 'Invalid or missing JWT token'
});
}
});