Skip to content

Commit

Permalink
updates user builder
Browse files Browse the repository at this point in the history
  • Loading branch information
sbpipb committed Apr 2, 2020
1 parent 5080556 commit f6ba3f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ def self.find_for_google_oauth2(auth)
user
end

# to refactor, could be single oauth method to begin with
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.provider + auth.uid).first_or_create do |user|
UserBuilder::Builder.build(user: user, auth: auth)
end
end

def google_access_token
google_access_token_expired? ? update_access_token : token
end
Expand Down Expand Up @@ -153,9 +160,4 @@ def oauth_provided?
def google_access_token_expired?
!access_expires_at || Time.zone.now > access_expires_at
end

# this ensures that uids are unique across providers
def provider_uid(auth)
auth.provider + auth.uid
end
end
1 change: 1 addition & 0 deletions app/services/user_builder/builder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module UserBuilder
class Builder
# Adds new omni auth providers here
SERVICE = {
# 'google_oauth' => GoogleOauth2
}
Expand Down

0 comments on commit f6ba3f4

Please sign in to comment.