diff --git a/frontend/src/auth/auth.controllers.js b/frontend/src/auth/auth.controllers.js index c64a3169152df1cb2fd05878cd8d905c55876dd7..253a44d1c3290a8e6bafd126af63602048c08fe3 100644 --- a/frontend/src/auth/auth.controllers.js +++ b/frontend/src/auth/auth.controllers.js @@ -31,8 +31,7 @@ AuthControllers.controller('Login', ['$scope', '$location', '$timeout', 'AuthUti // this is ridiculously stupid. we have to wait (300ms) for the cookie to actually be set in the browser :( $timeout(function() { - // we expect the homepage to handle the routing details about where the user should be going - $location.path('/'); + AppState.redirectAfterLogin(); }, 300); }, function (error) { $scope.$broadcast("form:api-error", error); diff --git a/frontend/src/services.js b/frontend/src/services.js index 534668c7e39acdb7a2439cddc6c11198781537dd..4d8bc5626b7fb8de203dc849666de224985450ba 100644 --- a/frontend/src/services.js +++ b/frontend/src/services.js @@ -22,7 +22,8 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva model: { setupToken: null, currentUser: null, - appContext: 'none' + appContext: 'none', + requestedUrl: null }, init: function() { @@ -157,8 +158,9 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva service.clearState(); if ($location.path().indexOf('/auth/') !== 0 && $location.path().indexOf('/setup/') !== 0) { - // if the user is asking for a url outside of /auth/* then send them to login page - // otherwise we will let the user continue on to their requested page + // if the user is asking for a url outside of /auth/* then record the url then send them + // to login page, otherwise we will let the user continue on to their requested page + service.model.requestedUrl = $location.path(); $location.path('/auth/login'); } @@ -173,6 +175,15 @@ MetabaseServices.factory('AppState', ['$rootScope', '$q', '$location', '$interva } } + }, + + redirectAfterLogin: function() { + if (service.model.requestedUrl) { + $location.path(service.model.requestedUrl); + delete service.model.requestedUrl; + } else { + $location.path('/'); + } } };