【发布时间】:2016-12-18 17:20:27
【问题描述】:
我正在 ionic 1.X 中构建聊天,我想使用 Firebase 作为我的数据库和身份验证提供程序。首先,我希望能够使用 Firebase 创建和登录用户。我在我的帐户中启用了简单的电子邮件和密码身份验证。但是,大多数像 one 这样的教程都适用于 Firebase 2。如果我遵循它,我会遇到下一个错误:
在我的 index.html 中,我像这样加载 firebase:
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/1.2.0/angularfire.min.js"></script>
然后创建一个用户:
$scope.signupEmail = function(){
$scope.message = null;
$scope.error = null;
console.log('In signup email with username ' + $scope.data.username + ' email ' + $scope.data.email + ' and password ' + $scope.data.password);
var chatRef = new Firebase('https://some-url.firebaseio.com');
var auth = $firebaseAuth(chatRef);
auth.$createUser({
email: $scope.data.email,
password: $scope.data.password
}).then(function(userData) {
console.log("User created with uid: " + userData.uid);
$scope.message = "User created with uid: " + userData.uid;
}).catch(function(error) {
console.log("Error: " + error);
$scope.error = error;
});
};
合乎逻辑的结论和搜索谷歌是我应该使用 Firebase 3 SDK 来创建用户。但是,如果我转到 index.html 并添加使用 firebase 的新方法,在官方 Ionic 文档(不是旧文档)中,您可以找到任何将新 SDK 与 Ionic 集成的部分:
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>
<script>
// Initialize Firebase
// TODO: Replace with your project's customized code snippet
var config = {
apiKey: "apiKey",
authDomain: "projectId.firebaseapp.com",
databaseURL: "https://databaseName.firebaseio.com",
storageBucket: "bucket.appspot.com",
};
firebase.initializeApp(config);
</script>
然后我无法将“firebase”注入我的模块。
知道如何集成 firebase sdk 3 和 ionic 1.x 吗?
【问题讨论】:
标签: ionic-framework firebase firebase-realtime-database firebase-authentication