Protect Routes with Plugs
Learn how to add session management in a Phoenix application
We'll cover the following...
The authentication service integrates with the Phoenix stack to provide infrastructure for session management including plugs that we can use in the router to control access to our routes.
Defining the authentication service
The authentication service is defined in the file pento/lib/pento_web/controllers/user_auth.ex
. We could open up the code base, but instead, let’s do a quick review in IEx
to see what the public API looks like.
Fire up the IEx in the terminal below with iex -S mix
, and key this in:
Press + to interact
exports PentoWeb.UserAuth
And, we should see exported plug functions like this:
Press + to interact
fetch_current_user/2log_in_user/2log_in_user/3log_out_user/1redirect_if_user_is_authenticated/2require_authenticated_user/2
All of ...