SHARE
TWEET

Untitled

a guest Aug 19th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. defmodule BlogApi.Plugs.SetUser do
  2.   import Plug.Conn
  3.  
  4.   alias BlogApi.Repo
  5.   alias BlogApi.Accounts.User
  6.  
  7.   def init(_params) do
  8.   end
  9.  
  10.   def call(conn, _params) do
  11.     if conn.assigns[:user] do
  12.       conn
  13.     else
  14.       session_uuid = get_session(conn, :user_uuid)
  15.  
  16.       cond do
  17.         user = session_uuid && Repo.get_by(User, uuid: session_uuid) ->
  18.           assign(conn, :user, user)
  19.  
  20.         true ->
  21.           assign(conn, :user, nil)
  22.       end
  23.     end
  24.   end
  25. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top