the-refinery / ember-devise-simple-auth

A plugin to integrate your Ember app with a (mostly stock) Devise setup
MIT License
84 stars 5 forks source link

Upgrading to newest javascript file constantly redirects to sign-in #22

Open jsonMartin opened 10 years ago

jsonMartin commented 10 years ago

The old version as of (March 11th/13th) works fine for me, but when upgrading to the newest version that deserializes the /sessions/current user information into ember data, it breaks the front-end functionality for me. The old version uses: currentSession, the new version uses: currentUser.

I am using ember-rails.

After some testing, I discovered the problem seems to be the new javascript code. The GEM upgrade still lets me access the /sessions/current information via rails (and still works when I leave the old index.js version in place), but when I try to replace the index.js file with the new version, it constantly redirects me to sign-in no matter what I do.

I tried both with and without a user model created in Ember.

Any help would be appreciated!

All the best,

Jason

jsonMartin commented 10 years ago

Also, below is a screenshot from my rails console.

When I enter the correct login info, I do get a Completed 201 for the _"/users/signin" request, and a Completed 200 OK for the "/sessions/current" request; however, nothing happens in the browser, nor are any messages are sent to the console after logging in (sending the action "signIn" request via login button)

image

abuiles commented 10 years ago

@jasoncartermartin hey Jason, how does your /sessions/current payload looks like? I guess you are using EmberData, make sure you are returning the user object as Ember Data expects, it should look something like

      {
        user: {
          id: 2,
          first_name: null,
          last_name: null,
          email: "foobar@gmail.com"
        }
      }
joefiorini commented 10 years ago

@jasoncartermartin to add on to @abuiles suggestion, also make sure you have skipsAuthentication: true on the routes that you are not wanting to secure. Otherwise, I'll try to look into it later when I have some time.

jsonMartin commented 10 years ago

Thanks for the quick response @abuiles and @joefiorini! Apologies for the delay in my response, I have been traveling extensively this week.

@joefiorini: Thanks for the skipsAuthentication tip; I'm currently just trying this on a route that I do want to be protected, but I'll keep this info in mind for the public facing sections of the webapp.

@abuiles: Yes, I am using Ember Data — here are the versions I am using:

DEBUG: -------------------------------
DEBUG: Ember      : 1.4.1+pre.af87bd20
DEBUG: Ember Data : 1.0.0-beta.7.f87cba88
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 1.11.0
DEBUG: ------------------------------- 

So, my /sessions/current payload looks like:

{
id: 1,
email: "jason.carter.martin@gmail.com",
created_at: "2014-03-15T20:54:20.000Z",
updated_at: "2014-03-22T18:16:35.000Z"
}

I'm guessing that since the JSON is not nested under "user", that this is causing it to fail?

Not sure the best way to fix this; I investigated to find out where to configure the /sessions/current route to modify it to try to nest under user, but all I could find in my project related to this was this code in routes.rb:

devise_scope :user do
    get "/sessions/current" => "ember_devise_simple_auth/sessions#show"
  end

What do you recommend as the best way to set up the /sessions/current rails response to format the data as expected?

And one last question: in addition to attempting to nest the /sessions/current rails response under "user", what do I need to have set up on the Ember side for User? I assume a model at bare minimum, but do I also need a controller/route set up for this on the Ember side for this to work as well? (When I look in the Ember inspector, the User model I created is not getting populated with data).

Thanks again for all of the help, and the work developing this project; It is great, and definitely the most elegant solution for getting Ember and Devise to play nicely :)

Cheers,

Jason

joefiorini commented 10 years ago

Are you using activemodelserializers for your data? If so, you can just create a user_serializer and it should be correct.

Let me know if that doesn't help.

--  Joe Fiorini

On March 22, 2014 at 2:39:46 PM, Jason Martin (notifications@github.com) wrote:

to

jsonMartin commented 10 years ago

Thanks @joefiorini, yes I am using ActiveModelSerializers. Tried your suggestion and it appears to be working now!

I was successfully able to set up a serializer for User, and now it returns the object as expected:

{
   user: {
   id: 1,
   email: "jason.carter.martin@gmail.com",
   current_sign_in_at: "2014-03-24T21:47:27.000Z"
   }
}

Now after logging in, it redirects me properly and the data is available in the User model when I check with Ember's Data inspector in Chrome.

Thanks for the help, I really appreciate it! I'll follow up if I run into any more issues.

All the best,

Jason

danbartlett commented 10 years ago

Had the exact same problem, although I had no idea it was anything to do with /sessions/current for a day and a half... Added the activemodelserializer and all is well, thanks everyone!