[AngularJS] $signInWithEmailAndPassword, comment l'utiliser ?

Par wolfgang59, il y a 9 ans


Bonjour,

Voila je rencontre un petit problème avec mon code au niveau du .$signInWithEmailAndPassword.
angular.js:13920 TypeError: Cannot read property '$signInWithEmailAndPassword' of undefined
En Plan B j'ai le script sur https://plnkr.co/edit/LDaSAuiV3Kc2KJk5eT7j?p=preview ... Mais bon... ça ne reprend pas toutes mes données.

Comment changer de type dans cette fonction ?

Merci,

Cordialement,

(function() { 'use strict'; angular .module('statusApp') .controller('AuthController', AuthController); function AuthController(Auth, User, $state) { var vm = this; vm.createUser = createUser; vm.login = login; function createUser() { // If there is already a user logged in, // log them out before proceeding Auth.$unauth(); Auth.$createUser({ email: vm.email, password: vm.password }).then(function(userData) { saveUser(userData); login() }).catch(function(error) { vm.error = error; }); } function saveUser(userData) { var user = User.newUserRef(userData); user.username = vm.username; user.email = vm.email; user.$save().then(function(success) { vm.username = null; vm.email = null; vm.password = null; $state.go('status'); }, function(error) { console.log("there was an error! " + error); }); } function login() { vm.Auth.$signInWithEmailAndPassword({ email: vm.email, password: vm.password }).then(function() { vm.email = null; vm.password = null; $state.go('status'); }).catch(function(error) { console.log(error); }); } } })();

2 réponses

Grafikart, il y a 9 ans

vm.Auth est undefined, pourquoi ne pas faire ? Auth.$sign....

wolfgang59, il y a 9 ans
        Bonjour,
        Merci. A cela mon collègue a rajouté ces modifs et ça marche. :)
        Auth.$signInWithEmailAndPassword(vm.email, vm.password)
            .then(function (data) {
                vm.email = null;
                vm.password = null;
                $state.go('status');