Authenticate The Live View
Understand how to implement user authentication in Phoenix LiveView by protecting routes and accessing session data. Learn to restrict LiveView routes to authenticated users, identify signed-in users using session tokens, and integrate authentication logic into your LiveView mount functions.
We'll cover the following...
Let’s integrate our wrong_live view with the authentication infrastructure. This quick test will let us make sure our infrastructure is working. When we’re done, we’ll understand how to protect authenticated LiveView routes and know how to identify the authenticated user in a LiveView.
We’ll start in the router by putting our live route behind authentication. Then, we’ll update our LiveView’s mount/3 function to use the token from the session to find the logged-in user.
How to protect sensitive routers
When we ran the generator earlier, a ...