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

Restricting access via sessions

We have some tests in place to make sure that our code works well enough, but we haven't done anything to actually secure the creation of new polls in our application. We want to make sure that the user is actually logged in - and if they're not, we need to be able to redirect them to the root page with a message explaining the situation. For this, we're going to write a Plug module so that we can reuse this code anywhere we need it. We'll call this VerifyUserSession, as that is the intended use case of the plug. Let's create lib/vocial_web/verify_user_session.ex and give it a starting skeleton, shown as follows:

defmodule VocialWeb.VerifyUserSession do  def init(opts), do: opts  def call(conn, _opts) do conn ...
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