Search code examples
node.jsmongodbrestexpressadmin

How companies assign the admin role to a user?


I am coding a Rest API with express and I have a middleware to check if a user is admin or not. However, I wonder how companies assign a new user as an admin? Do they edit the database record and change the role there?. I guess that one admin could make another user admin but how is the first admin created? Is there a way to do it in the frontend?


Solution

  • If it's a software platform (meaning one web address and database for all users of your app) then the first admin user is typically created by running commands on the server command line console to create the right record. Or perhaps by a setup script that is run once. This creates the first admin user, and then that user logs in and creates more admin users via the UI. This typically only ever needs to be done once in the entire lifetime of the project, so no need to have this be a user friendly process.

    However, if it's a server you install your own instance of it's common to have a setup wizard, since each new install will need to go through this process, it's worth the effort to make something user friendly. You go to something like myapp.com/setup and then complete a few forms that sets up the first admin user and provides initial configuration and preferences. After this first admin user is setup this setup page would no longer be accessible, so that no other new admin users can be created that way.

    Wordpress is a great example of the interactive setup. The end of this video has an example of what that looks like.