From d8b04cfdbbc1ff812713210ebf6dc5bd3ded2db0 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:44:43 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=F0=9F=94=A8`Authentication`=20Prev?= =?UTF-8?q?ent=20a=20condition=20when=20double-tapping=20sign-in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/zinc-collective/convene/issues/1809 OK, so my working assumption is that the bug is caused by two requests being processed at the same time for a new email address, and the first one creates the `AuthenticationMethod` and the second one *tries* to, and fails; resulting in the validation error. This fixes the racecondition at the controller level, but I think we want to do it at in AuthenticatedSession#save instead... --- app/controllers/authenticated_sessions_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/authenticated_sessions_controller.rb b/app/controllers/authenticated_sessions_controller.rb index 998917f0f..535617440 100644 --- a/app/controllers/authenticated_sessions_controller.rb +++ b/app/controllers/authenticated_sessions_controller.rb @@ -15,6 +15,13 @@ def create else render :create, status: :unprocessable_entity end + rescue ActiveRecord::RecordInvalid + @authenticated_session = nil + if authenticated_session.save + redirect_to(current_space.presence || :root) + else + render :create, status: :unprocessable_entity + end end alias_method :update, :create