简体   繁体   中英

How do I go about creating an admin user for my application?

I'm creating a book rental application using Express and Postgres. One feature I want to include in the app is an admin user that will be able to add books and perform other tasks that a 'normal' user cannot. I have created a 'user_account' table in Postgres with one field being a 'user_role'. Since I only want there to be one admin user I don't think I'm going about this the right way. I need suggestions on how to handle this issue. Is the 'user_role' field even necessary for the user table?

Since I only want there to be one admin user I

That is a weird thing to design your application around. Why not just make it possible for any number of people to be administrators, but then only assign the role to one person? You could even use a partial unique index to enforce that constraint, if you wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM