diff --git a/assets/scripts/app/auth.coffee b/assets/scripts/app/auth.coffee index fe9b2832..565a18c1 100644 --- a/assets/scripts/app/auth.coffee +++ b/assets/scripts/app/auth.coffee @@ -70,10 +70,9 @@ Travis.setLocale(data.user.locale || Travis.default_locale) Travis.trigger('user:signed_in', data.user) if router = Travis.__container__.lookup('router:main') - path = @readAfterSignInPath() Ember.run.next => try - router.send('afterSignIn', path) + router.send('afterSignIn') catch e throw e unless e =~ /There are no active handlers/ @refreshUserData(data.user) @@ -100,14 +99,6 @@ user.get('permissions') user - storeAfterSignInPath: (path) -> - Travis.sessionStorage.setItem('travis.after_signin_path', path) - - readAfterSignInPath: -> - path = Travis.sessionStorage.getItem('travis.after_signin_path') - Travis.sessionStorage.removeItem('travis.after_signin_path') - path - receiveMessage: (event) -> if event.origin == @expectedOrigin() if event.data == 'redirect' diff --git a/assets/scripts/app/routes.coffee b/assets/scripts/app/routes.coffee index 5b4049f4..8c9a8ccc 100644 --- a/assets/scripts/app/routes.coffee +++ b/assets/scripts/app/routes.coffee @@ -5,8 +5,6 @@ Ember.Router.reopen location: (if testMode? then Ember.NoneLocation.create() else Travis.Location.create()) handleURL: (url) -> - Travis.autoSignIn() unless Travis.__container__.lookup('controller:currentUser').get('content') - url = url.replace(/#.*?$/, '') try @_super(url) @@ -26,22 +24,35 @@ Ember.Route.reopen renderNoOwnedRepos: -> @render('no_owned_repos', outlet: 'main') + error: (error) -> + if error == 'needs-auth' + @transitionTo('auth') + else + throw(error) + afterSignIn: (path) -> @afterSignIn(path) afterSignOut: -> @afterSignOut() - afterSignIn: (path) -> - @routeToPath(path) + afterSignIn: -> + if transition = Travis.auth.get('afterSignInTransition') + Travis.auth.set('afterSignInTransition', null) + transition.retry() afterSignOut: -> - @routeToPath('/') + @transitionTo('index.current') - routeToPath: (path) -> - return unless path - @router.handleURL(path) - @router.location.setURL(path) + beforeModel: (transition) -> + Travis.autoSignIn() unless @signedIn() + + if !@signedIn() && @get('needsAuth') + Travis.auth.set('afterSignInTransition', transition) + transition.abort() + Ember.RSVP.reject("needs-auth") + else + @_super.apply(this, arguments) signedIn: -> @controllerFor('currentUser').get('content') @@ -65,7 +76,6 @@ Travis.Router.reopen @_super.apply this, arguments - Travis.Router.map -> @resource 'index', path: '/', -> @route 'current', path: '/' @@ -346,7 +356,7 @@ Travis.AccountRoute = Ember.Route.extend proxy serialize: (account) -> - if account + if account && account.get { login: account.get('login') } else {}