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

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

Open
jsonMartin opened this issue Mar 20, 2014 · 7 comments
Open

Comments

@jsonMartin
Copy link

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
Copy link
Author

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/sign_in" 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
Copy link
Contributor

abuiles commented Mar 20, 2014

@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
Copy link
Contributor

@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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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
Copy link

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!

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

No branches or pull requests

4 participants