Code Self Study Forum

An upcoming authentication solution for Phoenix (Elixir)

“An upcoming authentication solution for Phoenix”

https://dashbit.co/blog/a-new-authentication-solution-for-phoenix

Here are some interesting tidbits about the system:

  • It provides a registration page with session-based login/logout, account confirmation, password reset, and remember me cookies. You can also safely update your e-mail (it requires confirming the new address to become effective) and safely update your password - both operations require the current password.

  • The system uses only two database tables: one with the user information and another with all user tokens.

  • Currently there is no integration with an e-mail or SMS library. This will likely vary a lot per application, so we currently only log messages to the terminal. Developers will have to bring their favorite libraries for this. We have listed some options in the generated code.

  • The business domain code (the Phoenix context plus Ecto schemas) is only 340LOC which attests to the power of the platform. With docs, it jumps to roughly 600LOC. Note the code has been formatted by the Elixir formatter (so no code golfing).

  • The five controllers take only 230LOC. They are all relatively straight-forward and simply handle the return types from the business domain. The templates take 168LOC altogether - which you will most likely customize anyway.

  • The authentication system has 100% code coverage. The tests altogether take about 1100LOC. They are by far the biggest chunk of the code.