Answer the question
In order to leave comments, you need to log in
How to fix auth in firebase?
I am doing authorization using angular-fire and firebase. If you register and delete the account right away, everything is fine, but if you wait a while or restart the server, then the following error will occur during deletion: This operation is sensitive and requires recent authentication. Log in again before retrying this request.
Error code: auth/requires-recent-
login
Authorization controller code:
app.controller('authCtrl', ['$scope', 'Auth', '$location', function($scope, Auth, $location) {
$scope.authError = null;
$scope.userEmail = null;
$scope.auth = Auth;
// any time auth state changes, add the user data to scope
$scope.auth.$onAuthStateChanged(function(firebaseUser) {
$scope.firebaseUser = firebaseUser ? firebaseUser.email : null;
});
// Create User
$scope.createUser = function() {
$scope.authError = null;
Auth.$createUserWithEmailAndPassword($scope.email, $scope.password)
.then(
function(firebaseUser) {
$location.path('/contacts');
$scope.userEmail = firebaseUser.email;
},
function(error) {
$scope.authError = error.message;
}
);
};
// Delete User
$scope.deleteUser = function() {
$scope.authError = null;
Auth.$deleteUser().then(
function() {
$location.path('/auth');
$scope.userEmail = null;
},
function(error) {
$scope.authError = error.message + ' ' + error.code;
}
)
};
// LogIn
$scope.logIn = function() {
Auth.$signInWithEmailAndPassword($scope.email, $scope.password)
.then(
function(firebaseUser) {
$location.path('/contacts');
$scope.userEmail = firebaseUser.email;
},
function(error) {
$scope.authError = error.message;
}
);
};
}]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question