Skip to content

PhoenixKit progress: Accounts, passwordless log-in and roles for Phoenix apps

The first part of PhoenixKit is working: user accounts and roles for Phoenix LiveView apps, the piece every one of our apps needs before anything else.

Accounts

A visitor can register, confirm their email address, log in and out, reset a forgotten password and change their own settings. All of it runs as LiveView pages that the kit adds to your router under its own path, so they don’t collide with your routes.

We added magic links as well: a user can ask for a log-in link by email and sign in without a password. It is handy for internal tools and for people who never remember passwords.

Your own LiveViews and controllers get the signed-in user from PhoenixKit (phoenix_kit_current_user, or the scope in phoenix_kit_current_scope), and on_mount hooks protect a page for signed-in users or admins only.

Roles

PhoenixKit comes with three built-in roles:

  • Owner, the account with full control. The first person to register becomes the Owner automatically, and the role can’t be handed out by accident.
  • Admin, for people who manage the app.
  • User, everyone else.

Apps can add their own roles, and checking one is a single call:

PhoenixKit.Users.Roles.user_has_role?(user, "Admin")

Next

An admin panel to manage all of this without a console.