get_req_header("authorization")
|> get_token()
|> Auth.authenticate()
|> handle_authentication(conn)
end
def handle_authentication({:ok, session: session, user: user}, conn) do
conn
|> assign(:current_user, user)
|> assign(:current_session, session)
end
def handle_authentication({:error, error}, conn) do
conn
|> put_status(:unauthorized)
|> render(ErrorView, "401.json", %{})
|> halt()
end {:ok, token} @spec authenticate(String.t) :: … X @spec authenticate({:ok, String.t} | {:error, atom}) :: … Please fix.