Skip to content

Instantly share code, notes, and snippets.

@janjiss
Created December 14, 2015 13:27
Show Gist options
  • Save janjiss/c2a087aee80e54e45009 to your computer and use it in GitHub Desktop.
Save janjiss/c2a087aee80e54e45009 to your computer and use it in GitHub Desktop.
defmodule ElixirStream.Plugs.CheckAuthentication do
import Plug.Conn
import Plug.Session
def init(options) do
options
end
def call(conn, _) do
user_id = get_session(conn, :user_id)
if session_present?(user_id) do
assign(conn, :current_user, ElixirStream.Repo.get(ElixirStream.User, user_id))
else
conn
end
end
def session_present?(user_id) do
case user_id do
nil -> false
_ -> true
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment