Skip to content

Commit

Permalink
feat: add account deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
zvonimirr committed Jun 16, 2024
1 parent 3edd49d commit 361ae7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/swipex/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ defmodule Swipex.User do
end
end

def delete_user_by_id(id) do
conn = Bolt.Sips.conn()

Bolt.Sips.query(
conn,
"""
MATCH (u:User {id: $id})
DETACH DELETE u
""",
%{id: id}
)
end

def get_potential_match(id) do
conn = Bolt.Sips.conn()

Expand Down
13 changes: 13 additions & 0 deletions lib/swipex_web/live/profile_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ defmodule SwipexWeb.ProfileLive do
end
end

def handle_event("delete", _, socket) do
case Swipex.User.delete_user_by_id(socket.assigns.user["id"]) do
{:ok, _} ->
{:noreply,
socket
|> redirect(to: "/logout")}

{:error, _} ->
{:noreply, socket |> put_flash(:error, "Failed to delete account.")}
end
end

def handle_info({:new_user, name}, socket) do
{:noreply, put_flash(socket, :info, "#{name} has arrived!")}
end
Expand Down Expand Up @@ -128,6 +140,7 @@ defmodule SwipexWeb.ProfileLive do
</div>
<hr />
<a href="/logout" class="text-red-500">Logout</a>
<button phx-click="delete" class="bg-red-500 text-white">Delete account</button>
</div>
"""
end
Expand Down

0 comments on commit 361ae7e

Please sign in to comment.