Class: SpreeCmCommissioner::UserIdTokenAuthenticator

Inherits:
BaseInteractor show all
Defined in:
app/interactors/spree_cm_commissioner/user_id_token_authenticator.rb

Instance Method Summary collapse

Instance Method Details

#callObject

:id_token



4
5
6
7
8
9
10
11
12
13
14
# File 'app/interactors/spree_cm_commissioner/user_id_token_authenticator.rb', line 4

def call
  context.user = if checker.user.nil?
                   register_user
                 else
                   checker.user
                 end

  update_user_email if context.user.email.blank?

  context.fail!(message: 'account_temporarily_deleted') if context.user.soft_deleted?
end

#checkerObject



29
30
31
32
# File 'app/interactors/spree_cm_commissioner/user_id_token_authenticator.rb', line 29

def checker
  @checker ||= SpreeCmCommissioner::UserIdTokenChecker.call(id_token: context.id_token)
  @checker
end

#register_userObject



16
17
18
19
# File 'app/interactors/spree_cm_commissioner/user_id_token_authenticator.rb', line 16

def register_user
  register_context = SpreeCmCommissioner::UserRegistrationWithIdToken.call(id_token: context.id_token)
  register_context.user
end

#update_user_emailObject



21
22
23
24
25
26
27
# File 'app/interactors/spree_cm_commissioner/user_id_token_authenticator.rb', line 21

def update_user_email
  firebase_context = FirebaseIdTokenProvider.call(id_token: context.id_token)
  return unless firebase_context.success?

  email = firebase_context.provider[:email]
  context.user.update(email: email) if email.present?
end