Consider this hypothetical situation:
- A user attempts to access a /settings page without being logged in.
- The Settings controller detects based on
$auth.isAuthenticated() != true
that the user is not logged in, and directs them to the /login page. - The user provides their email and password and submits the form.
In the third step, I wish to redirect them to the /settings page instead of the home page.
I am contemplating updating this variable:
$authProvider.loginRedirect = '/';
The issue arises when attempting to include $authProvider
in my loginCtrl.js
file, resulting in an "unknown provider" error in the console: https://docs.angularjs.org/error/$injector/unpr?p0= In essence, Angular does not recognize $authProvider
when it is added. This is how the loginCtrl.js
file appears:
/* Challenges arise from trying to integrate $authProvider */
angular.module("PrayerChain")
.controller("loginCtrl", ["$rootScope", "$scope", "$state", "$http", "$auth", "$authProvider", loginCtrl]);
function loginCtrl($rootScope, $scope, $state, $http, $auth, $authProvider) {
$authProvider.loginRedirect = '/settings';
$scope.login = function () {
$auth.login({ Email: $scope.email, Password: $scope.password })
.then(function() {
})
.catch(function (response, status, headers) {
console.log(response);
$scope.error = JSON.parse(response.data);
});
};
}
Is it feasible to include $authProvider
within a controller? If not, what other approach can be taken to alter the redirection destination after logging in using Satellizer?
Thank you.