miniature-optician-85831
11/29/2023, 1:13 PMbetter-restaurant-41251
11/29/2023, 1:21 PMruby
class Avo::UsersController < Avo::ResourcesController
around_action :create_cognito_user, only: :create
private
def create_cognito_user
ActiveRecord::Base.transaction do
yield
user = @resource.model
cognito_user = cognito_client.create_user(user)
user.update_column(:cognito_id, cognito_user.user.username)
end
end
def cognito_client
@cognito_client ||= CognitoClient.new
end
end
This approach sorta worked… when the DB operation was successful, my Cognito user was created. When there was a DB failure—like dupe email addresses—the controller would roll back the transaction and prevent the user from being created in Cognito.
The problem is that this approach also mucks up the create_fail_action so we get an error page instead of the nice flash/turbo notification.loud-jewelry-99127
11/29/2023, 1:30 PMcreate_fail_action and / or create_success_action?loud-jewelry-99127
11/29/2023, 1:33 PMruby
def create_success_action
# some_logic_here
super
endlemon-wall-20836
11/29/2023, 2:41 PMlemon-wall-20836
11/29/2023, 2:41 PMlemon-wall-20836
11/29/2023, 2:42 PMsuperbetter-restaurant-41251
11/30/2023, 7:14 PMlemon-wall-20836
12/01/2023, 11:21 AMlemon-wall-20836
12/01/2023, 11:21 AM