DEV Community

Cover image for Authentication in Phoenix Framework Using Guardian - Boilerplate Code
Mike CK
Mike CK

Posted on • Updated on • Originally published at mikeck.elevatika.com

Authentication in Phoenix Framework Using Guardian - Boilerplate Code

As mentioned in the comments by David:

Phoenix now has its own auth written by Jose Valim and Aaron Renner - github.com/aaronrenner/phx_gen_auth

Therefore the method below might be unnecessary..


Here is the repo Barebones Phoenix 1.5.1 Project Using Guardian for Authentication

The protected route is /products. All other routes are free to access.

For some weird reason, the project won't compile under Windows since it requires Argon2_elixir (which requires native compilation that is not easy to set up).

To get the project working, I used WSL from within VS Code and everything works 100%.

Installing Elixir and Its Tools in WSL


wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb
sudo apt-get update
sudo apt-get install esl-erlang
sudo apt-get install elixir
sudo apt-get install build-essential
mix archive.install hex phx_new 1.5.1
sudo apt-get install -y inotify-tools

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bas
nvm install --lts
Enter fullscreen mode Exit fullscreen mode

In case you need to access a PostgreSQL instance that you installed inside Windows, you can do:

sudo apt install postgresql-client-common
sudo apt-get install postgresql-client
psql -h 127.0.0.1 -p 5432 -U postgres

Enter fullscreen mode Exit fullscreen mode

To start your Phoenix server:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.setup
  • Install Node.js dependencies with cd assets && npm install
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check deployment guides.

Learn more

Top comments (2)

Collapse
 
wulymammoth profile image
David

Phoenix now has its own auth written by Jose Valim and Aaron Renner - github.com/aaronrenner/phx_gen_auth

Collapse
 
mikeck profile image
Mike CK • Edited

Thanks for this! awesome. Really, authentication is the most basic requirement in almost any web app. Sorry I saw this comment late. :)