enforce token authorization

master
Stefan Haslinger (root) 2022-03-25 08:46:31 +01:00
parent 64d49fea81
commit 088351899e
1 changed files with 23 additions and 11 deletions

View File

@ -11,6 +11,11 @@ defmodule WeatherTrackerWeb.WeatherConditionsController do
def create(conn, params) do
IO.inspect(params)
token =
get_req_header(conn, "authorization")
|> List.first()
if token == "shiqbNfVhL91JZOtqK0896BYJfZbUDrI2ERIzmoc" do
case WeatherConditions.create_entry(params) do
{:ok, weather_condition = %WeatherCondition{}} ->
Logger.debug("Successfully created a weather condition entry")
@ -26,5 +31,12 @@ defmodule WeatherTrackerWeb.WeatherConditionsController do
|> put_status(:unprocessable_entity)
|> json(%{message: "Poorly formatted payload"})
end
else
Logger.warn("No valid auth token provided")
conn
|> put_status(:unprocessable_entity)
|> json(%{message: "Auth token not valid"})
end
end
end