我正在尝试在我的 Ionic Angular 项目上设置 Firebase。我正在使用链接教程https://www.positronx.io/ionic-firebase-authentication-tutorial-with-examples/来做到这一点。
我不断收到 TS2570 错误:
'Promise' 类型不存在属性 'sendEmailVerification'。您是否忘记使用“等待”?
我附上了我的代码。我唯一改变的主要事情是 AngularFire 改变了 6.0.0 中使用 auth 的方式
import { Injectable, NgZone } from '@angular/core';
import { auth } from 'firebase/app';
import { User } from "./user";
import { Router } from "@angular/router";
import { AngularFireAuth } from "@angular/fire/auth";
import { AngularFirestore, AngularFirestoreDocument } from '@angular/fire/firestore';
@Injectable({
providedIn: 'root'
})
export class AuthenticationService {
userData: any;
constructor(
public afStore: AngularFirestore,
public ngFireAuth: AngularFireAuth,
public router: Router,
public ngZone: …Run Code Online (Sandbox Code Playgroud) 我想我已经接近了,我能够打印出属于用户的书籍的ID,但是从firebase书籍参考中一直尝试获取属于用户的书籍列表是不成功的.
我在这里松散地阅读教程:http: //www.thinkster.io/pick/eHPCs7s87O/angularjs-tutorial-learn-to-rapidly-build-real-time-web-apps-with-firebase#item-526e9330d90f99661f00046c
并在此处阅读有关非规范化数据的文档:https: //www.firebase.com/blog/2013-04-12-denormalizing-is-normal.html
如果我想在页面中显示用户,然后是所有书籍,我应该怎么做呢?
FB
|
--user
| |
| --user1
| |
| --name: "test name"
| --email: "test@test.com"
| --books
| |
| "-JFZG3coHOAblHZ7XSjK": true
| "-KJKJASDIUOPIWE9WEeJ": true
| "-YtUTRGJLNL876F3SSwS": true
|
--books
|
--"-JFZG3coHOAblHZ7XSjK"
| |
| --title: "book title 1"
| --ownerId: "user1"
|
--"-KJKJASDIUOPIWE9WEeJ"
| |
| --title: "book title 2"
| --ownerId: "user1"
|
--"-YtUTRGJLNL876F3SSwS"
| |
| --title: "book title 2"
| --ownerId: "user1"
Run Code Online (Sandbox Code Playgroud)
<div …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular和Firebase以及UI路由器.我正在使用匿名身份验证.当会话到期时,我希望将未经身份验证的用户重定向到主页.我使用了Yeoman Angularfire Generator作为模型.但是当我使用下面的代码时,当用户已经在该页面上并且会话到期时,经过身份验证的页面不会重定向.
.config(['$urlRouterProvider', 'SECURED_ROUTES', function($urlRouterProvider, SECURED_ROUTES) {
$urlRouterProvider.whenAuthenticated = function(path, route) {
route.resolve = route.resolve || {};
route.resolve.user = ['Auth', function(Auth) {
return Auth.$requireAuth();
}];
$urlRouterProvider.when(path, route);
SECURED_ROUTES[path] = true;
return $urlRouterProvider;
};
}])
.run(['$rootScope', '$location', 'Auth', 'SECURED_ROUTES', '$state',
function($rootScope, $location, Auth, SECURED_ROUTES, $state) {
Auth.$onAuth(check);
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
if (error === 'AUTH_REQUIRED') {
$state.go('home');
}
else {
console.log('authenticated');
}
});
function check(user) {
if (!user && authRequired($location.path())) {
$state.go('home');
}
}
function authRequired(path) …Run Code Online (Sandbox Code Playgroud) angularjs firebase firebase-security angularfire angular-ui-router
我正在使用 Ionic 和 Firebase 为当地一家餐馆开发食品订购应用程序。由于对任何后端语言的知识有限,而且懒得花时间在这上面,我想使用 Firebase 来存储数据,因为它拥有我需要的一切。我只是怀疑在整个应用程序的生产中使用它是否是个好主意。预计每天大约有 10-20 个订单(一开始),我也怀疑该应用程序每天会吃掉的空间,以及我应该订阅什么计划。
谢谢
我正在开发一个angularfire项目,我想知道如何在Firebase 3中创建用户,一旦完成,不要对指定用户进行身份验证.在之前的Firebase版本中,我们使用了名为createUser(email,password)的方法.现在我们只有createUserWithEmailAndPassword(电子邮件,密码)方法,它创建并验证指定的用户.
有趣的是,从今天早上开始,我已经使用了AngularCrashlytics(from @angular/fire)一段时间,我无法得到buildor ,ng serve这会引发如下错误。有人可以帮助我摆脱这个吗?
我app.module已经添加了@angular/fire相关的配置步骤,如下所示(取自https://github.com/angular/angularfire/blob/master/docs/analytics/getting-started.md)
import { AngularFireModule } from '@angular/fire/compat';
import { AngularFireAnalyticsModule } from '@angular/fire/compat/analytics';
imports:[
AngularFireModule.initializeApp(environment.Tools.Firebase)//firebase releated config,
AngularFireAnalyticsModule
]
Run Code Online (Sandbox Code Playgroud)
package.json 中的依赖版本
"firebase": "^9.14.0",
"@angular/fire": "^7.4.1"
Run Code Online (Sandbox Code Playgroud)
附加说明:已经从头开始克隆的项目多次尝试删除node modules文件夹,npm install此外还尝试将 firebase 和 @angular/fire 升级到最新版本,但没有解决问题。
在angularFire示例中,它显示了如何从firebase获取对象集合.
app.controller('ctrl', ['$scope', '$timeout', 'angularFireCollection',
function($scope, $timeout, angularFireCollection) {
var url = 'https://ex.firebaseio.com/stuff';
$scope.col = angularFireCollection(url);
}
]);
Run Code Online (Sandbox Code Playgroud)
那只是一个对象呢?
我试过这样的事情:
fb.child('stuff/'+id).on('value', function(snapshot) {
$scope.obj = snapshot.val();
console.log('hey got the value')
console.log(snapshot.val())
});
Run Code Online (Sandbox Code Playgroud)
似乎没有用.控制台正确输出对象值,但控制器不更新.
我最近在Thinkster上学习了一个使用Angular和Firebase创建Web应用程序的教程.
本教程使用Firebase simpleLogin方法允许创建包含用户名的"配置文件".
厂:
app.factory('Auth', function($firebaseSimpleLogin, $firebase, FIREBASE_URL, $rootScope) {
var ref = new Firebase(FIREBASE_URL);
var auth = $firebaseSimpleLogin(ref);
var Auth = {
register: function(user) {
return auth.$createUser(user.email, user.password);
},
createProfile: function(user) {
var profile = {
username: user.username,
md5_hash: user.md5_hash
};
var profileRef = $firebase(ref.child('profile'));
return profileRef.$set(user.uid, profile);
},
login: function(user) {
return auth.$login('password', user);
},
logout: function() {
auth.$logout();
},
resolveUser: function() {
return auth.$getCurrentUser();
},
signedIn: function() {
return !!Auth.user.provider;
},
user: {} …Run Code Online (Sandbox Code Playgroud) 因此,每当我从Firebase注销时,我都会加入
Error: permission_denied: Client doesn't have permission to access the desired data.
Run Code Online (Sandbox Code Playgroud)
我理解这是因为登录会话终止,我的一些对象无法再访问firebase数据.但是如何在注销前断开此对象?
对于我的Ionic View中的注销按钮,它只需调用firebase服务:
function logout() {
auth.$unauth();
getCurrentUser();
};
function getCurrentUser() {
var authData = auth.$getAuth();
if (authData) {
$rootScope.userId = authData.uid;
$rootScope.currentUser = $firebaseObject(authRef.child("users").child(authData.uid));
return $rootScope.currentUser;
} else {
console.log("User is not login!");
$rootScope.userId = null;
$location.path("/auth/signin");
if ($rootScope.currentUser) {
$rootScope.currentUser.$destroy();
}
}
};
Run Code Online (Sandbox Code Playgroud)
所以我在那里销毁$ rootScope.currentUser.我为配置文件页面使用相同的getCurrentUser.因此错误没有以这种方式出现.但是在其他视图中,我有另一个$ firebaseArray,还有另一个Ref.on("child_added",函数(snap)与$ firebaseObject相同.当我查看配置文件页面时,此页面至少有3个firebase连接,当我退出时,我有3个permission_denied错误(注销按钮在用户个人资料页面上).
我的问题是,在注销之前如何断开此firebase连接?有没有办法断开所有firebase连接 - 无论是AngularFire还是常规的Firebase?所以我可以注销而不用担心哪个firebase连接没有关闭呢?此外,由于Logout按钮位于Profile范围内,而其他连接位于不同的范围内,因此我不知道如何关闭甚至在配置文件范围内的连接...
我有一个Angular 8应用程序,使用npm包Angular Firebase(https://github.com/angular/angularfire2),当我使用Angular CLI命令构建应用程序并将其ng build --prod部署到主机时,出现以下Chrome浏览器控制台错误:
TypeError: Object(...)(...).auth is not a function
Run Code Online (Sandbox Code Playgroud)
如果我改用命令构建,ng build --prod --optimization=false则不会发生错误。
Angular CLI ng build选项optimization设置为true的情况导致AngularFire2 npm软件包错误。
我不确定如何进一步调试此问题。这是我的package.json文件:
{
"name": "bigmoenyshot",
"version": "8.0.0",
"license": "https://themeforest.net/licenses/terms/regular",
"scripts": {
"ng": "ng",
"serve": "ng serve",
"serveProd": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve --prod --optimization=true",
"build": "ng build --prod=true --aot=true --extractCss=true --optimization=true",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"deploy": "ng build --prod=true --aot=true --extractCss=true --optimization=false && firebase deploy"
},
"private": true, …Run Code Online (Sandbox Code Playgroud) angularfire ×10
firebase ×10
angularjs ×6
angular ×3
javascript ×2
typescript ×2
crashlytics ×1