How to create first user (Admin)?
I have backend, users can create accounts, each account has role - admin or user. I want the first account to be Admin. Should I create it during database seeding or every time user register their account I check if it's first user and give him admin role? Or is there a better way?
Aslo accounts must be verified to log in to it and only admin users can verify other user account.
6 Replies
I think both ways are very much practical.
As seen before, a fresh installation gives you welcome screen where you create the first user account that'll be the superadmin.
This approach ensures that they have to create an useraccount with their credentials and that there's no default superadmin credentials. - Once again, it depends on your application and use-case.
yeah i've used software that works both ways
jenkins has a first run process where you have to grab an auto-generated secret it put on the filesystem to create the first account
Okay, then I'll check if account is the first one and give him admin role
keep in mind if the website is deployed publicly that might be an issue, since theoretically someone could get there first and make the account
Very unlikely, but possible.
But, are we talking about a web-service or a desktop/mobile-app? 😄
On the latter you could use an Installation-Wizard/Manager.
It's just a small website for me and friends so it won't be a problem 😀