We are working on an app with lazy auth - for example we have a comment form where a user can type a comment. If they aren’t logged in, when they click “submit” they are prompted to sign in. I have already implemented ember-auth and have sign in working, but we are trying to figure out the best way to handle completing the original action after a successful sign in.
Ideally I think we’d like
sign in and
sign up actions in their own routes, and although we could create an action on the application router that supports a callback method as an argument (could also be wired up as a promise, which I’ll probably do), I’m not sure how to handle routing back to the current route automatically. For example:
App.PostRoute = Ember.Route.extend actions: createComment: -> @send "requireAuth", => ... App.ApplicationRoute = Ember.Route.extend actions: requireAuth: (callback) -> # 1. store the current route some how # 2. add an observer to transition back to current route # and fire the callback upon sign in # 3. transition to signIn Route
There are plenty of examples for protecting a route (
ember-auth even has it built in), but I can’t seem to find any best-practice examples for just protecting a route action. I have thought about going in a direction where we don’t have actual
signUp routes, and just have a top level route action that renders the views into the application outlet, and then upon sign in re-calling
renderTemplate on the current route, that just seems kind of hacky imo.