Skip to main content

Admin Setup

By default no user is assigned as an Admin. So we have to manually add an Admin for the very first time.

  • Open your backend code then go to this path src -> routes -> administrator.js. Then scroll down to the end of the page, you will see /make-admin path. This path is commented in to disable access. Remove the comment and activate the path.
// Make Admin
// 🔴 Remember to disable the below portion after you make an admin

// router.post(
// "/make-admin",
// validators.administrator.makeAdminOnce,
// middlewares.validateRequest,
// controllers.administrator.makeAdminOnce
// );

Make it like below:

  // Make Admin
// 🔴 Remember to disable the below portion after you make an admin

router.post(
"/make-admin",
validators.administrator.makeAdminOnce,
middlewares.validateRequest,
controllers.administrator.makeAdminOnce
);

Activate Make Admin Path on Backend

  • Run your backend using npm start command. Your backend should run on http://localhost:8000 port.
  • Run your frontend using npm run dev command. It should run your frontend on http://localhost:3000 port.
  • Now visit http://localhost:3000 and create an account.
  • By default you will become a normal user, without any administrative capabilities.
  • Now our task is to make you an Admin.
  • Download and Install MongoDB Compass from https://www.mongodb.com/products/tools/compass
  • Open MongoDB compass, and create a new connection using your MongoDB connection string.
  • Then you will get to see your MongoDB data there.
  • Go to users data. There you will see your account information.
  • Copy the value of _id, for example it looks something like ObjectId('6775020a7e5ad4d6da9d1989'). We just need the value, that is 6775020a7e5ad4d6da9d1989.

Get MongoDB User Id

  • Now we will make an API request to our server to make this user an Admin.
  • You can use any API request making tool like Postman, or you can use online tool like https://apirequest.io/
  • From your API request making tool, select Request type to POST request.
  • Set the API URL to http://localhost:8000/api/administrator/make-admin
  • In request Bodysection, click x-www-form-urlencoded the write Key as id and Value as6775020a7e5ad4d6da9d1989. Remember to place your own id here.
  • Then send the request. It will make the requested user an admin.

Send Postman API request to Backend

  • Important: Now go to your backend code and comment out the/make-admin path, so that no one get the access to this path again.
info

Remember the make-admin only runs for once. If you have at least 1 admin, it'll not run.

  • Now logout from the frontend and login again, you will see the Admin privileges in your account. You can further manage admins from the frontend dashboard.