Skip to content

Commit

Permalink
Retrieve omniauth_identity automatically when accessed for first ti…
Browse files Browse the repository at this point in the history
…me (#29)

I often forget to call `retrieve_omniauth_identity` before trying to
access the `omniauth_identity` attribute in
`before_omniauth_callback_route`.

I think we can make it automatically retrieve `omniauth_identity` the
first time it's called.

I haven't removed the `retrieve_omniauth_identity` method since it might
already be called by users.
  • Loading branch information
enescakir authored Dec 27, 2024
1 parent 5e4d95d commit e15b67d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/rodauth/features/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ def handle_omniauth_callback
def _handle_omniauth_callback
before_omniauth_callback_route

retrieve_omniauth_identity

if !account && omniauth_identity
account_from_omniauth_identity
end

unless account
account_from_omniauth
if omniauth_identity
account_from_omniauth_identity
else
account_from_omniauth
end
end

if account && !open_account?
Expand Down Expand Up @@ -100,8 +98,12 @@ def _handle_omniauth_callback
end
end

def omniauth_identity
@omniauth_identity ||= retrieve_omniauth_identity
end

def retrieve_omniauth_identity
@omniauth_identity = _retrieve_omniauth_identity(omniauth_provider, omniauth_uid)
_retrieve_omniauth_identity(omniauth_provider, omniauth_uid)
end

def account_from_omniauth_identity
Expand Down Expand Up @@ -142,8 +144,6 @@ def after_close_account
remove_omniauth_identities
end

attr_reader :omniauth_identity

def omniauth_second_factor?
features.include?(:two_factor_base) && uses_two_factor_authentication? && omniauth_two_factors?
end
Expand Down

0 comments on commit e15b67d

Please sign in to comment.