Reputation: 17480
I'm trying to make it so that when you visit a given path you would be redirected to the login route.
I followed the code in this gist, but it hasn't seemed to have any effect in my app (Everything still works the way it did before, but at least nothing broke)
My Code:
App.AuthenticatedRoute = Ember.Route.extend
beforeModel: (transition) ->
if !App.Auth.signedIn
return RSVP.reject();
App.PromptsRoute = App.AuthenticatedRoute
model: -> App.Prompt.find()
error: (reason, transition) ->
loginController = @controllerFor('login')
loginController.set('afterLoginTransition', transition)
@transitionTo(login)
App.LoginController = Ember.Controller.extend
email: null
password: null
remember: true
loginError: null
afterLoginTransition: null
login: () ->
self = @
App.Auth.signIn
data:
email: @get 'email'
password: @get 'password'
remember: @get 'remember'
.done (response) ->
self.clearForm()
self.loginSucceeded()
.fail (response) ->
self.set('loginError', "Your username or password was incorrect. Please try again")
clearForm: ->
self.set('loginError', null)
self.set('email', null)
self.set('password', null)
self.set('recmember', true)
loginSucceeded: ->
transition = @get('afterLoginTransition')
if transition
transition.retry()
else
alert("Boink")
Upvotes: 0
Views: 123
Reputation: 23322
I guess you wanted to extend the AuthenticatedRoute
rather than assigning it to your AuthenticatedRoute
, right?
If it's the case you should do:
App.PromptsRoute = App.AuthenticatedRoute.extend
model: -> App.Prompt.find()
...
Hope it helps.
Upvotes: 1