Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cybrox/3c15f2966ce417451f3f3cdd36614b6b to your computer and use it in GitHub Desktop.
Save cybrox/3c15f2966ce417451f3f3cdd36614b6b to your computer and use it in GitHub Desktop.
Blog: Testing Protected Phoenix Controllers - Snippet 1
def authenticate_user_token(conn, _opts) do
with ["Bearer " <> token] <- get_req_header(conn, "authorization"),
{:ok, %{:id => user_id}} <- Token.verify_user_for_token(token),
conn_assign_user_details(conn, user_id)
else
_ -> send_unauthorized_if_not_faked(conn)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment