2018-11-06 10:30:27 +01:00
|
|
|
defmodule MobilizonWeb.Context do
|
2019-01-03 14:59:59 +01:00
|
|
|
@moduledoc """
|
|
|
|
Guardian context for MobilizonWeb
|
|
|
|
"""
|
2018-11-06 10:30:27 +01:00
|
|
|
@behaviour Plug
|
|
|
|
|
|
|
|
import Plug.Conn
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
def init(opts) do
|
|
|
|
opts
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(conn, _) do
|
|
|
|
case Guardian.Plug.current_resource(conn) do
|
|
|
|
nil ->
|
|
|
|
conn
|
|
|
|
|
|
|
|
user ->
|
|
|
|
put_private(conn, :absinthe, %{context: %{current_user: user}})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|