freshkitedev / LMS-Project

Welcome to the LMS / Learning Management System Full stack Project
1 stars 6 forks source link

User Authorization #12

Closed Vishva77 closed 6 months ago

Vishva77 commented 6 months ago

Authentication Middleware (isAuthenticated):

Verifies if a user is authenticated by checking for an access token in the request cookies. Decodes and verifies the access token using JWT. Retrieves user data from Redis based on the token's decoded user ID. Attaches the user data to the request object (req.user) if authenticated.

Authorization Middleware (authorizeRoles):

Validates if the authenticated user has required role(s) to access a resource. Compares the user's role with specified roles and returns an error if access is forbidden.

Type Declaration for Express Request Object:

Extends the request object's type definition to include a user property of type IUser, representing the structure of a user model.

commit id : e047b45d3fd08389bd66206ee329dcecb9a6ab35