is there any way to set up the prebuilt auth system without using phoenix_html? I’m trying to use the mix phx.gen.auth
command, but I’m not server-side rendering the HTML. Is there another way to make it work, or are there other options?
** (Mix) mix phx.gen.auth requires phoenix_html
mix phx.gen.auth must be installed into a Phoenix 1.5 app that
contains ecto and html templates.
mix phx.new my_app
mix phx.new my_app --umbrella
mix phx.new my_app --database mysql
Apps generated with --no-ecto or --no-html are not supported.
If you just want the auto-generated files here’s what I would do:
cd /tmp
mix phx.new same_project_name_as_your_real_app
cd same_project_name_as_your_real_app
git init
git add -A
git commit -m "Some message"
mix phx.gen.auth Accounts User users
This will generate all the required files, and the console will output a list of created and modified files.
From there, you can copy the needed files over to your real project. Since there was a Git commit made before running the generators (ALWAYS make a Git commit before running the generators), you can inspect the modified (“injected”) files manually with git diff
to see what modifications were made to the existing files.
Then, you can painstakingly modify the files until it works, then make a Git commit and hang onto it forever so you never have to re-visit the problem ever again.
But FYI, the auth generator assumes you are rendering the HTML. If you want a token auth system or something like that, you would need to modify the generators to get the desired functionality.
You might also be better off with something like Guardian or Pow for your auth if you are straying too far from the golden path that works best with the Phoenix auth generator.
3 Likes