Skip to content

Commit

Permalink
Normalize sign up responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjay-w committed Jan 27, 2025
1 parent b0d26e3 commit daa0a54
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/controllers/api/v1/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def create
begin
duplicate_user = User.get_duplicate_user(resource.email, [])[:user]
user = resource
error = [
{
message: I18n.t(:email_exists)
}
]
if !duplicate_user.nil? && duplicate_user.invited_to_sign_up?
duplicate_user.accept_invitation_or_confirm
duplicate_user.password = resource.password
Expand All @@ -28,19 +33,14 @@ def create

User.current = user
sign_up(resource_name, user)
render_success user, 'user', 401
render_success user, 'user', 401, error
rescue ActiveRecord::RecordInvalid => e
# Check if the error is specifically related to the email being taken
if resource.errors.details[:email].any? { |error| error[:error] == :taken } && resource.errors.details.except(:email).empty?
# Treat as successful sign-up if only the email is taken
duplicate_user = User.get_duplicate_user(resource.email, [])[:user]
User.current = duplicate_user if duplicate_user
sign_up(resource_name, duplicate_user)
error = [
{
message: I18n.t(:email_exists)
}
]
render_success nil, 'user', 401, error
else
# For other errors, show the error message in the form
Expand Down

0 comments on commit daa0a54

Please sign in to comment.