isaacsanders / omniauth-stripe-connect

Stripe Connect OAuth2 Strategy for OmniAuth 1.0
MIT License
130 stars 74 forks source link

undefined method `provider' for nil:NilClass #53

Closed ddonche closed 6 years ago

ddonche commented 6 years ago

I have followed every step in the recommended tutorial (linked in the documentation of this gem) here. Whenever I click the button I created to send a user to Stripe to get their stripe info and update the database, I get an error. I am clicking the button while logged in as a user, and I have all the fields in my database.

undefined method 'provider' for nil:NilClass Specifically, this line:

provider: request.env["omniauth.auth"].provider, initializers/devise.rb

config.omniauth :stripe_connect,
    ENV['STRIPE_CONNECT_CLIENT_ID'],
    ENV['STRIPE_SECRET_KEY'],
    :scope => 'read_write',
    :stripe_landing => 'register'

I have these in my .env file.

routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" } omniauth_callback_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def stripe_connect
    @user = current_user
    if @user.update_attributes({
      provider: request.env["omniauth.auth"].provider,
      uid: request.env["omniauth.auth"].uid,
      access_code: request.env["omniauth.auth"].credentials.token,
      publishable_key: request.env["omniauth.auth"].info.stripe_publishable_key
    })
      # anything else you need to do in response..
      sign_in_and_redirect @user, :event => :authentication
      set_flash_message(:notice, :success, :kind => "Stripe") if is_navigational_format?
    else
      session["devise.stripe_connect_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

  def failure
    # If we do get failures we should probably handle them more explicitly than just rerouting to root. To review in the future with colo
    redirect_to root_path
  end
end

and the button in the view:

<%= link_to image_tag('icons/blue-on-light.png'), user_stripe_connect_omniauth_callback_path(:stripe_connect) %> schema.rb

create_table "users", force: :cascade do |t|
    ...
    t.string   "uid"
    t.string   "provider"
    t.string   "access_code"
    t.string   "publishable_key"
  end
isaacsanders commented 6 years ago

@ddonche Did you fix this on your own?