Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Friendly "404 Not Found" When No API Key is Found #54

Closed
nelsonic opened this issue Apr 27, 2020 · 1 comment
Closed

Display Friendly "404 Not Found" When No API Key is Found #54

nelsonic opened this issue Apr 27, 2020 · 1 comment
Labels
enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished starter A beginner-friendly issue that is a good starting point for a new person

Comments

@nelsonic
Copy link
Member

I keep resetting the Database to test Auth and when the API Key I created is no longer there,
I see this error:

Ecto.NoResultsError at GET /profile/apikeys/7
expected at least one result but got none in query:
from a0 in Auth.Apikey,
  where: a0.id == ^"7"

image

We need a better 404 error with some styling.

@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished starter A beginner-friendly issue that is a good starting point for a new person labels Apr 27, 2020
@nelsonic
Copy link
Member Author

This has been fixed by having a "special" key for the SuperAdmin that gets created during setup:

auth/priv/repo/seeds.exs

Lines 36 to 54 in fafc5e0

def create_apikey_for_admin(person) do
{:ok, key} =
%{
"name" => "system admin key",
"description" => "Created by /priv/repo/seeds.exs during setup.",
# the default host in %Plug.Conn
"url" => "www.example.com"
}
|> AuthWeb.ApikeyController.make_apikey(person.id)
|> Auth.Apikey.create_apikey()
api_key = key.client_id <> "/" <> key.client_secret
# Set the AUTH_API_KEY to a valid value that is in the DB:
System.put_env("AUTH_API_KEY", api_key)
IO.inspect(System.get_env("AUTH_API_KEY"), label: "AUTH_API_KEY")
IO.puts("- - - - - - - - - - - - - - - - - - - - - - ")
key
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished starter A beginner-friendly issue that is a good starting point for a new person
Projects
None yet
Development

No branches or pull requests

1 participant