Update the phoenix version and starting migration the project.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
defmodule LinkShortenerWeb.Auth.ErrorHandler do
|
||||
import Plug.Conn
|
||||
|
||||
def auth_error(conn, {type, _reason}, _opts) do
|
||||
body = Poison.encode!(%{error: to_string(type)})
|
||||
conn
|
||||
|> put_resp_content_type("application/json")
|
||||
|> send_resp(401, body)
|
||||
end
|
||||
end
|
||||
@@ -1,31 +0,0 @@
|
||||
defmodule LinkShortenerWeb.Auth.Guardian do
|
||||
use Guardian, otp_app: :link_shortener
|
||||
|
||||
alias LinkShortener.Accounts
|
||||
alias LinkShortener.Accounts.User
|
||||
|
||||
def subject_for_token(user, _claims) do
|
||||
sub = to_string(user.id)
|
||||
{:ok, sub}
|
||||
end
|
||||
|
||||
def resource_from_claims(claims) do
|
||||
id = claims["sub"]
|
||||
resource = Accounts.get_user!(id)
|
||||
{:ok, resource}
|
||||
end
|
||||
|
||||
def authenticate(email, password) do
|
||||
with user <- Accounts.get_user_by_email_and_password(email, password) do
|
||||
case user do
|
||||
%User{} -> create_token(user)
|
||||
nil -> {:error, :unauthorized}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_token(user) do
|
||||
{:ok, token, _claims} = encode_and_sign(user)
|
||||
{:ok, user, token}
|
||||
end
|
||||
end
|
||||
@@ -1,9 +0,0 @@
|
||||
defmodule LinkShortenerWeb.Auth.Pipeline do
|
||||
use Guardian.Plug.Pipeline, otp_app: :link_shortener,
|
||||
module: LinkShortenerWeb.Auth.Guardian,
|
||||
error_handler: LinkShortenerWeb.Auth.ErrorHandler
|
||||
|
||||
plug Guardian.Plug.VerifyHeader
|
||||
plug Guardian.Plug.EnsureAuthenticated
|
||||
plug Guardian.Plug.LoadResource
|
||||
end
|
||||
Reference in New Issue
Block a user