diff --git a/src/js/main.js b/src/js/main.js index 20f4da0d0..fb095ac82 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -76,6 +76,17 @@ angular.module('Application').controller('MainController', ['$scope', '$route', refreshNotifications(); }; + function redirectOnMandatory2FA() { + if (Client.getConfig().mandatory2FA && !Client.getUserInfo().twoFactorAuthenticationEnabled) { + $location.path('/profile').search({ setup2fa: true }); + } + } + + // Make it redirect if the browser URL is changed directly - https://forum.cloudron.io/topic/7510/bug-in-2fa-force + $scope.$on('$routeChangeStart', function (/* event */) { + if ($scope.initialized) redirectOnMandatory2FA(); + }); + function init() { Client.getStatus(function (error, status) { if (error) return Client.initError(error, init); @@ -138,10 +149,7 @@ angular.module('Application').controller('MainController', ['$scope', '$route', $scope.initialized = true; - if (Client.getConfig().mandatory2FA && !Client.getUserInfo().twoFactorAuthenticationEnabled) { - $location.path('/profile').search({ setup2fa: true }); - return; - } + redirectOnMandatory2FA(); $interval(refreshNotifications, 60 * 1000); refreshNotifications();