How to bootstrap (admin) accounts without public registration page?

I’m working on an internal project at work where we don’t want to have a registration page open to the public. The team is small, so we can easily manage with a more manual, but closed, process (i.e., an admin creating a registration magic link for a new user).

The problem is, who creates the first admin? My initial thought was I’d write a Mix task mix foo.register --email foo@bar.com, however, my understanding is that Mix tasks aren’t available on releases.

Any ideas on how to solve this problem? And more generally, how do people usually implement companion programs/subcommands for Elixir projects?

Thanks in advance!

You can start an iex shell connected to your production release and execute arbitrary commands, such as creating users.

(You can use the remote subcommand)

2 Likes

Oh nice! I missed that whole section of the page, I knew about start/stop, but not the others.

To confirm I understood it right, though – let’s say I have the project running as a service (SystemD or what have you), if I then SSH into the server and run /path/to/foo remote, it starts a new Elixir shell connected to the running foo project?

Correct.

If you prefer to write scripts, have a look at mix release — Mix v1.19.5 and the “Helper Module” section. Also look at the files generated when you create a release, that will give you inspiration for how you can encapsulate reusable commands for operating your project.

1 Like

Cool, thanks a lot!

1 Like

Ok just add the user with the hashed passwords to your seeds