Created
May 20, 2013 14:17
-
-
Save joefiorini/5612528 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How you could do what you want in Ember | |
App.Router.map(function(){ | |
this.resource("userSession", function(){ | |
this.route("new", { path: "/sign-in" }); | |
}) | |
}); | |
// However, any time you create a resource you have an extra layer of routing | |
// & a model that you may/may not want. In the case of sign-in, which doesn't | |
// really represent part of the UI, I'd consider just using a route instead. | |
App.Router.map(function(){ | |
this.route("signIn", { path: "/sign-in" }); | |
}); | |
// Then in your controller you can set the current session on ApplicationController | |
App.SignInController = Ember.Controller.extend({ | |
signIn: function(){ | |
var session = UserSession.validate(this.get("username"), this.get("password")); // assuming you have some object with a session token or something | |
this.controllers("application").set("session", sesssion); | |
} | |
}); |
I think the biggest reason you're having a hard time is that it's a security risk. There cannot be any chance the user can disable the auth check and start getting protected data. I'm sure you've already considered those implications though :)
You are correct on the purpose of UserSession.validate
. You have to be careful with cookies & ajax requests; I'm not sure how browsers handle cookies in ajax responses but I seem to remember it being a no-no in some; don't remember which. You could also just use document.cookies to set it manually in Javascript.
Also, not sure if you saw this but this looks like an interesting approach:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Honestly I just had a really hard time finding an example online using devise w/ ember that didn't rely on logging in via a traditional webpage then passing you to the ember app. I wanted to make it all work in ember so that site was the best I found. Happy to look at alternatives.
In your approach I'm guessing the UserSession.validation method would make the request to the devise backend and if valid would return back the session token. How does this play with a "remember me?" style thing? I suppose it's just a cookie which would get set like normal on the web request so the auth call would just check if they are already logged in.