April 2018
Beginner to intermediate
406 pages
9h 33m
English
Let's start by taking a look at some of the session code that we wrote in the previous chapter to get a better sense of the shape of the data we're currently storing in the session. This will help us understand how to pull the data back out of the session and use it appropriately, shown as follows:
conn |> put_flash(:info, "Logged in successfully!") |> put_session(:user, %{ id: login_user.id, username: login_user.username, email: login_user.email }) |> redirect(to: "/")
The preceding code places a key into the session storage called :user, so that's what we'll use to get the user ID back out of the session. Let's dive into our poll controller code to properly set the user ID inside of our creation with statement, ...