gpt4 book ai didi

javascript - $createUser(credentials) - Firebase 创建 Slack 的克隆

转载 作者:行者123 更新时间:2023-11-30 21:20:22 30 4
gpt4 key购买 nike

https://thinkster.io/tutorials/angularfire-realtime-slack-clone/creating-the-auth-controller

/* 授权服务 */

angular 
.module('angularfireSlackApp')
.factory('Auth', function($firebaseAuth, FirebaseUrl){

var ref = firebase.database().ref();
var auth = $firebaseAuth();

return auth;

});

/* 授权 Controller */

angular.module('angularfireSlackApp') 
.controller('AuthCtrl', function(Auth, $state){

var authCtrl = this;

authCtrl.user = {

email:'',
password:''
}

authCtrl.login = function(){
Auth.$authWithPassword(authCtrl.user).then(function (auth){
$state.go('home');
}, function(error){

authCtrl.error = error;
});
};

authCtrl.register = function(){
Auth.$createUser(authCtrl.user).then(function (user){
authCtrl.login();
}, function(error){
authCtrl.error = error;
});
};


});

Google Chrome 控制台抛出此错误。

TypeError: Auth.$authWithPassword is not a function
at Object.authCtrl.login (auth.controller.js:13)
at fn (eval at compile (angular.js:15500), <anonymous>:4:179)
at callback (angular.js:27285)
at ChildScope.$eval (angular.js:18372)
at ChildScope.$apply (angular.js:18472)
at HTMLFormElement.<anonymous> (angular.js:27290)
at defaultHandlerWrapper (angular.js:3771)
at HTMLFormElement.eventHandler (angular.js:3759)

This is for the login.

& For the register.

TypeError: Auth.$createUser is not a function
at Object.authCtrl.register (auth.controller.js:22)
at fn (eval at compile (angular.js:15500), <anonymous>:4:182)
at callback (angular.js:27285)
at ChildScope.$eval (angular.js:18372)
at ChildScope.$apply (angular.js:18472)
at HTMLFormElement.<anonymous> (angular.js:27290)
at defaultHandlerWrapper (angular.js:3771)
at HTMLFormElement.eventHandler (angular.js:3759)

我想我需要学习另一个教程。事情似乎已经过时了。您能否帮助我,让我知道我是否应该继续使用相同的代码并尝试调试和更改一些东西以使其正常工作或从头开始?

最佳答案

用这些解决

authCtrl.login = function (){
Auth.$signInWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password).then(function (auth){
$state.go('home');
}, function (error){
authCtrl.error = error;
});
};

authCtrl.register = function (){
Auth.$createUserWithEmailAndPassword(authCtrl.user.email, authCtrl.user.password).then(function (user){
$state.go('home');
}, function (error){
authCtrl.error = error;
});
};

关于javascript - $createUser(credentials) - Firebase 创建 Slack 的克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45253077/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com