From 188c556233929fef1fb48c3b19c0745c15ee9920 Mon Sep 17 00:00:00 2001 From: Firehose Bot Date: Mon, 6 Jul 2026 10:55:15 +0100 Subject: [PATCH] Fix demo user confirmation to allow password login The seeds file was creating an unconfirmed user and then setting a password, which conflicts with Phoenix's auth system (magic link login is not allowed for unconfirmed users with passwords). This fix ensures the demo user is confirmed before setting their password, so they can log in via both magic link and password. Demo credentials: demo@example.com / password123! --- app/priv/repo/seeds.exs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/priv/repo/seeds.exs b/app/priv/repo/seeds.exs index 36dbe87..ecf461c 100644 --- a/app/priv/repo/seeds.exs +++ b/app/priv/repo/seeds.exs @@ -11,11 +11,29 @@ # and so on) as they will fail if something goes wrong. if Mix.env() == :dev do + import Ecto.Query alias Firehose.Accounts - # Create demo user if not already present - unless Accounts.get_user_by_email("demo@example.com") do + # Get or create demo user + user = Accounts.get_user_by_email("demo@example.com") + + unless user do {:ok, user} = Accounts.register_user(%{email: "demo@example.com"}) + end + + # Ensure user is confirmed to allow password login and avoid magic link conflicts + if is_nil(user.confirmed_at) do + Firehose.Repo.update_all( + from(u in Accounts.User, where: u.email == ^"demo@example.com"), + set: [confirmed_at: DateTime.utc_now()] + ) + + # Reload user after confirmation + user = Accounts.get_user_by_email("demo@example.com") + end + + # Set password if not already set + unless user.hashed_password do {:ok, {_user, _tokens}} = Accounts.update_user_password(user, %{password: "password123!"}) end end