title: Rails: Heroku with Omniauth and Facebook
body: <p>I am working on an app that allows you to authenticate with Facebook to signup and log into the app. For some reason when working with multiple dynos, it appears that session management isn't carried over.</p>
  
  <p>I can watch my logs log the user in, but when the user is redirected, the app logs the user out for some reason</p>
  
  <p>Here is my AuthorizationsController:</p>
  
  <pre><code>class AuthorizationsController &lt; ApplicationController
    skip_before_filter :redirect_to_signed_in_path, :prepare_for_mobile, :redirect_to_https, :force_www!
  
    def create
      authentication = Authorization.find_by_provider_and_uid(auth['provider'], auth['uid'])
  
      if authentication
        flash[:notice] = "Signed In Successfully"
        sign_in authentication.user, event: :authentication
        redirect_to root_path
      elsif user_signed_in?
        current_user.apply_omniauth(auth)
  
        if current_user.save
          current_user.update_attribute(:"allow_#{auth['provider']}_sync", true)
          PullSocialActionsWorker.perform_async(current_user.id, auth["provider"])
          redirect_to edit_social_profile_path, flash: { error: "#{auth["provider"]} Integration is processing" }
        else
          redirect_to edit_social_profile_path, flash: { error: "An error has occurred. Please try again." }
        end
  
      else
        password = Devise.friendly_token[0,20]
        athlete = Athlete.new(email: generate_auth_email(params[:provider]), password: password, password_confirmation: password )
        athlete.apply_omniauth(auth)
  
        begin
          athlete.subscriptions.build(trial_expiry: DateTime.now + 30, active: true, account_type_id: AccountType.free.id)
          if athlete.save(validate: false)
            sign_in athlete, event: :authentication
            redirect_to root_path, notice: "Account created and signed in successfully"
          else
            redirect_to root_path, flash: { error: "An error has occurred. Please try again." }
          end
        rescue ActiveRecord::RecordNotUnique
          redirect_to root_path, flash: { error: "The email address you are trying to connect already exists. Perhaps you #{ActionController::Base.helpers.link_to "Forgot Your Password?", new_user_password_path}".html_safe }
        end
      end
    end
  
    def failure
      redirect_to root_url, notice: "An Error has occurred. Please try again!"
    end
  
    private
  
      def auth
        request.env["omniauth.auth"]
      end
  
      def generate_auth_email(provider)
        if provider == "twitter"
          "#{auth.uid}@twitter.com"
        else
          auth.info.try(:email)
        end
      end
  
  end
  </code></pre>
  
  <p>Gemfile:</p>
  
  <pre><code>gem 'omniauth'
  gem 'omniauth-facebook', '1.4.0'
  </code></pre>
  
  <p>I am also using Memcache/Dalli for caching...</p>
  
  <pre><code>gem 'memcachier'
  gem 'dalli'
  </code></pre>
  
  <p>Anyone else run into this issue before?</p>