Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

Retrieving data from sessions

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, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content