mirror of
https://github.com/System-End/hackatime.git
synced 2026-04-20 00:35:22 +00:00
Fix slack signin after email address update
This commit is contained in:
parent
3bfaa354f2
commit
0c8cddfef1
1 changed files with 7 additions and 1 deletions
|
|
@ -145,13 +145,19 @@ class User < ApplicationRecord
|
|||
return nil unless user_data["ok"]
|
||||
|
||||
user = find_or_initialize_by(slack_uid: data.dig("authed_user", "id"))
|
||||
user.email = user_data.dig("user", "profile", "email")
|
||||
user.username = user_data.dig("user", "profile", "username")
|
||||
user.username ||= user_data.dig("user", "profile", "display_name_normalized")
|
||||
user.avatar_url = user_data.dig("user", "profile", "image_192") || user_data.dig("user", "profile", "image_72")
|
||||
# Store the OAuth data
|
||||
user.slack_access_token = data["authed_user"]["access_token"]
|
||||
user.slack_scopes = data["authed_user"]["scope"]&.split(/,\s*/)
|
||||
|
||||
# Handle email address
|
||||
if email = user_data.dig("user", "profile", "email")
|
||||
# Find or create email address record
|
||||
user.email_addresses.find_or_initialize_by(email: email)
|
||||
end
|
||||
|
||||
user.save!
|
||||
user
|
||||
rescue => e
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue