Add the logout for the API.
continuous-integration/drone/push Build is failing

This commit is contained in:
2024-08-31 14:47:45 +03:00
parent 2f4fc790be
commit 3eb12de52c
9 changed files with 94 additions and 6 deletions
@@ -22,5 +22,12 @@ defmodule LinkShortenerWeb.Api.V1.AccountsController do
|> put_status(:created)
|> render(:user, %{user: user, token: token})
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
+12
View File
@@ -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