This commit is contained in:
@@ -23,4 +23,12 @@ defmodule LinkShortenerWeb.Api.V1.AccountsController do
|
||||
|> render(:user, %{user: user, token: token})
|
||||
end
|
||||
end
|
||||
|
||||
def sign_out(conn, %{}) do
|
||||
token = Guardian.Plug.current_token(conn)
|
||||
Guardian.revoke(token)
|
||||
conn
|
||||
|> put_status(:ok)
|
||||
|> render(:sign_out, %{token: token})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,15 @@ defmodule LinkShortenerWeb.Api.V1.AccountsJSON do
|
||||
|
||||
def user(%{user: user, token: token}) do
|
||||
%{
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
token: token
|
||||
}
|
||||
end
|
||||
|
||||
def sign_out(%{token: token}) do
|
||||
%{
|
||||
message: "Successfully sign out",
|
||||
token: token
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,10 @@ defmodule LinkShortenerWeb.Router do
|
||||
plug :accepts, ["json"]
|
||||
end
|
||||
|
||||
pipeline :auth do
|
||||
plug LinkShortenerWeb.Auth.Pipeline
|
||||
end
|
||||
|
||||
scope "/", LinkShortenerWeb do
|
||||
pipe_through :browser
|
||||
|
||||
@@ -30,6 +34,14 @@ defmodule LinkShortenerWeb.Router do
|
||||
scope "/v1", Api.V1, as: :v1 do
|
||||
post "/users/sign_up", AccountsController, :sign_up
|
||||
post "/users/sign_in", AccountsController, :sign_in
|
||||
end
|
||||
end
|
||||
|
||||
scope "/api", LinkShortenerWeb do
|
||||
pipe_through [:api, :auth]
|
||||
|
||||
scope "/v1", Api.V1, as: :v1 do
|
||||
post "/users/sign_out", AccountsController, :sign_out
|
||||
|
||||
resources "/links", LinkController
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user