isaacsanders / omniauth-stripe-connect

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

User is nil after call back #42

Closed Hatcher19 closed 7 years ago

Hatcher19 commented 7 years ago

when the user is coming back from stripe, @user is nil. Thus triggering the else in the if statement in my omniauth_callbacks_controller.rb.

class OmniauthCallbacksController < ApplicationController
  def stripe_connect
    p @user
    @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

end

How do I pass @ user to stripe so I can get it returned?

isaacsanders commented 7 years ago

Would the state parameter work?

crifat commented 7 years ago

Hi, any update on this issue?

isaacsanders commented 7 years ago

@nigh7m4r3 I had just asked a question 4 days ago...

isaacsanders commented 7 years ago

Also, I don't think current_user is a thing in omniauth. I thought it was a devise thing.

isaacsanders commented 7 years ago

It looks like the OP might be using Devise incorrectly. I think it needs to be a subclass of Devise::OmniauthCallbacksController

crifat commented 7 years ago

@isaacsanders After I commented, I solved it and I forgot about this. Thank you for being responsive. The problem was so straightforward! OmniauthCallbacksController was inheriting from ApplicationController and there is the problem. It requires authentication. I think @Hatcher19 had the same problem. I changed it to Devise::OmniauthCallbacksController . Thanks to the state parameter. I was able to pass user_id to get it again in the stripe_connect method.

Thank you

isaacsanders commented 7 years ago

@nigh7m4r3 @Hatcher19 Let me know if there are any further problems. Closing for now.