Admin User v1
This commit is contained in:
@@ -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'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user