Skip to content

Commit

Permalink
Decouple api token controller from User schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jun 18, 2024
1 parent b7f8c86 commit abb425a
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/asciinema_web/controllers/api_token_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule AsciinemaWeb.ApiTokenController do
use AsciinemaWeb, :controller
alias Asciinema.Accounts.User

plug :require_current_user

Expand Down Expand Up @@ -43,12 +42,12 @@ defmodule AsciinemaWeb.ApiTokenController do
end

defp redirect_to_profile(conn) do
path =
case conn.assigns.current_user do
%User{username: nil} -> ~p"/username/new"
%User{} = user -> profile_path(user)
end
user = conn.assigns.current_user

redirect(conn, to: path)
if user.username do
redirect(conn, to: profile_path(user))
else
redirect(conn, to: ~p"/username/new")
end
end
end

0 comments on commit abb425a

Please sign in to comment.