Skip to content

Commit

Permalink
Fixed: now all user can logout and login many times.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenSanzas committed Oct 4, 2024
1 parent f59f178 commit 701461f
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions app/services/user_service.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
# app/services/user_service.rb
class UserService
def self.find_or_create_user(auth)
uid = auth["uid"]
email = auth["info"]["email"]
names = auth["info"]["name"].split
first_name = names[0]
last_name = names[1..].join(" ")

if Rails.env.test?
email_to_find = email.present? ? email : "spongey@tamu.edu"
user = UserRepository.find_by_email(email_to_find)
end

unless user
user = UserRepository.create_user(
uid: uid,
email: email,
first_name: first_name,
last_name: last_name
)
Role.create(user_id: user.id, role: "Member")
end

user
uid = auth["uid"]
email = auth["info"]["email"]
names = auth["info"]["name"].split
first_name = names[0]
last_name = names[1..].join(" ")

user = UserRepository.find_by_uid(uid) || UserRepository.find_by_email(email)

unless user
user = UserRepository.create_user(
uid: uid,
email: email,
first_name: first_name,
last_name: last_name
)

if user.nil? || user.id.nil?
Rails.logger.error("User creation failed for email: #{email}")
raise "User creation failed"
end

Role.create!(user_id: user.id, role: "Member") unless user.roles.exists?
end

user
end

def self.find_user_by_id(id)
UserRepository.find_by_id(id)
UserRepository.find_by_id(id)
end

def self.fetch_all
UserRepository.fetch_all
UserRepository.fetch_all
end
end
end

0 comments on commit 701461f

Please sign in to comment.