Created
December 14, 2015 13:27
-
-
Save janjiss/c2a087aee80e54e45009 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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