# Bypass the account creation modal when using OAuth2

**URL:** <https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123>\
**Category:** Product Support\
**Created:** [26 בפברואר,‏ 2019,‏ 1:23pm UTC](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123 "2019-02-26T13:23:56Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [1 במרץ,‏ 2019,‏ 11:55am UTC](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123/9 "2019-03-01T11:55:04Z")

</div>

Try moving that code directly underneath

```plaintext
elsif SiteSetting.oauth2_email_verified?

```

and change `user` to `result.user`

```plaintext
  def after_authenticate(auth)
    log("after_authenticate response: \n\ncreds: #{auth['credentials'].to_hash}\ninfo: #{auth['info'].to_hash}\nextra: #{auth['extra'].to_hash}")

    result = Auth::Result.new
    token = auth['credentials']['token']
    user_details = fetch_user_details(token, auth['info'][:id])

    result.name = user_details[:name]
    result.username = user_details[:username]
    result.email = user_details[:email]
    result.email_valid = result.email.present? && SiteSetting.oauth2_email_verified?
    avatar_url = user_details[:avatar]

    current_info = ::PluginStore.get("oauth2_basic", "oauth2_basic_user_#{user_details[:user_id]}")
    if current_info
      result.user = User.where(id: current_info[:user_id]).first
    elsif SiteSetting.oauth2_email_verified?
      # --------------
      if User.find_by_email(user_details[:email]).nil?
        result.user = User.create(name: user_details[:name], email: user_details[:email], username: user_details[:username])
        log("created user account")
      end
      # --------------

      result.user = User.find_by_email(result.email)
      if result.user && user_details[:user_id]
        ::PluginStore.set("oauth2_basic", "oauth2_basic_user_#{user_details[:user_id]}", user_id: result.user.id)
      end
    end

    download_avatar(result.user, avatar_url)

    result.extra_data = { oauth2_basic_user_id: user_details[:user_id], avatar_url: avatar_url }

    result
  end

```

Note that modifying code in this way isn’t great, because it will break if we update the method later. This will almost certainly require maintenance in the future.

---

_[View the full topic](https://meta.discourse.org/t/bypass-the-account-creation-modal-when-using-oauth2/110123)._
