From abb425adbc867284d1e3950a2f2ee82ab1267ce1 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Tue, 18 Jun 2024 15:24:40 +0200 Subject: [PATCH] Decouple api token controller from User schema --- .../controllers/api_token_controller.ex | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/asciinema_web/controllers/api_token_controller.ex b/lib/asciinema_web/controllers/api_token_controller.ex index 1f8721c64..02238e888 100644 --- a/lib/asciinema_web/controllers/api_token_controller.ex +++ b/lib/asciinema_web/controllers/api_token_controller.ex @@ -1,6 +1,5 @@ defmodule AsciinemaWeb.ApiTokenController do use AsciinemaWeb, :controller - alias Asciinema.Accounts.User plug :require_current_user @@ -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