Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Make authorisation middleware for admin role #42

Closed
1 task done
anand-harsh opened this issue Jan 15, 2024 · 8 comments
Closed
1 task done

Backend: Make authorisation middleware for admin role #42

anand-harsh opened this issue Jan 15, 2024 · 8 comments
Assignees
Labels
assigned issue is assigned to someone backend working on backend feature new feature to be added JWOC JWOC open source program medium 4 points

Comments

@anand-harsh
Copy link
Owner

Issue

As anyone can add course to playlist or remove it from playlist, so we do not want this full authority to be given to users

Solution

  1. Make a middleware "adminAuthorisation" for the admin with role.
  2. If user is having role "admin" then only he can perform the task of addition or deletion.
  3. if any user without admin role tries to do the task then return "Not Allowed" with 403 status code.
  4. Add middlewares to " /createcourse" and POST request for " /course/:id"
  • JWOC
@anand-harsh anand-harsh added not-assigned issue is not assigned to someone JWOC JWOC open source program hard 8 points feature new feature to be added backend working on backend labels Jan 15, 2024
@anand-harsh anand-harsh added medium 4 points and removed hard 8 points labels Jan 15, 2024
@Anushkabh
Copy link
Contributor

@anand-harsh i would like to work on this. kindly assign under JWOC

@Divyanshgarg-04
Copy link
Contributor

@anand-harsh I would love to work on this issue under JWOC. Van you please assign this issue to me

@anand-harsh anand-harsh added assigned issue is assigned to someone and removed not-assigned issue is not assigned to someone labels Jan 17, 2024
@Divyanshgarg-04
Copy link
Contributor

@anand-harsh /course/:id route is not defined

@anand-harsh
Copy link
Owner Author

@anand-harsh /course/:id route is not defined

In API (backend)

@Divyanshgarg-04
Copy link
Contributor

image

in courseRoutes.js file there are only two routes defined

@anand-harsh
Copy link
Owner Author

image

in courseRoutes.js file there are only two routes defined

Then make it.

@Divyanshgarg-04
Copy link
Contributor

@anand-harsh It should be get request rather than post?

@anand-harsh
Copy link
Owner Author

anand-harsh commented Jan 17, 2024

@anand-harsh It should be get request rather than post?

We are not making crud operation here so no need of post or get. We are making middleware which will be later used in get or post request routes to limit the access of normal user to that route.

Here what you can do is, take token from cookie, decode that token to get id, check the role for that id, if the role of that id is admin, return next() else return ErrorHandler("cant access") with a status code.

Hope you get it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assigned issue is assigned to someone backend working on backend feature new feature to be added JWOC JWOC open source program medium 4 points
Projects
None yet
Development

No branches or pull requests

3 participants