Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise session reset on subsequent request #3623

Closed
adamnoto opened this issue Jun 6, 2015 · 7 comments
Closed

Devise session reset on subsequent request #3623

adamnoto opened this issue Jun 6, 2015 · 7 comments

Comments

@adamnoto
Copy link

adamnoto commented Jun 6, 2015

I used:

Devise (3.5.1)
Omniauth (1.2.2)
Warden (1.2.3)

On a trial project, a new one using Mongoid as the ORM. Sessions controller are created anew, and used, instead of the Devise's standard, and changed into:

class UserDevise::SessionsController < Devise::SessionsController
  def new
    super
  end

  def create
    puts "AUTH OPTIONS"
    puts auth_options
    self.resource = warden.authenticate!(auth_options)
    puts "RESOURCE"
    puts self.resource.inspect
    set_flash_message(:notice, :signed_in) if is_flashing_format?
    sign_in(resource_name, resource)
    yield resource if block_given?

    session[:whatever] = "ADAM PAHLEVI"

    puts session.keys

    flash.delete(:notice)

    if current_user.data.prereg
      if params[:original_url]
        redirect_to params[:original_url]
      else
        redirect_to main_app.root_path
      end
    else
      # prereg_path
      redirect_to main_app.root_path
    end
  end

  def destroy
    signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
    super
    flash.delete(:notice)
  end
end

My session (whatever) is persisted, but Warden's session is reset on subsequent request. I don't know why.

@josevalim
Copy link
Contributor

Are you doing sign up with ajax or something like that? In any case, it is very hard to find out what is wrong with such a code snippets, so Can you please provide a sample application that reproduces the error?

@adamnoto
Copy link
Author

adamnoto commented Jun 6, 2015

No Ajax. I am new to Git, should I set up a new repo for this? I used git mainly only to push something.

@adamnoto
Copy link
Author

adamnoto commented Jun 6, 2015

I already undergone several test in different rails version. And, the strange thing is not in the devise itself, but rather in MongoDB, or should i say... mongoid?

If a mongo db is shared by two different app... what happen is that, you can login (under same devise configuration) but the session won't persist.

I don't know if this is a mongo/rails/devise problem...

@adamnoto
Copy link
Author

adamnoto commented Jun 6, 2015

I confirm that there's problem with sharing mongodb database for devise's user login.

I used an entirely new project, new, as in "rails new." First, with a separate database, everything is OK. Then, I changed the db to use the same mongoid db, and then problem begin to occur: that is, session not persisted.

Strange...

@scottlowe
Copy link

@saveav Are you still seeing this issue? I am using Devise and Mongoid and may have a similar problem - I seem to be losing authenticated state within Warden. Trying to work out if this is related.

@josevalim
Copy link
Contributor

Which mongoid version are you using? It was a mongoid bug which should hopefully be fixed.

@scottlowe
Copy link

Using Mongoid 4.0.2. So this should be fixed in Devise 3.5.2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants