我正在关注安装了最新版AngularFire(0.8.0)的Thinkster Ang-News教程.我已成功地成功完成本教程的第7部分,但我仍然遇到需要将用户对象插入Firebase Forge的部分.代码的工作原理如下:
当新用户通过我的HTML表单注册时,将调用"register"函数并调用"User.create(authUser,$ scope.user.username);" 在"寄存器"功能中执行.
// login and registration page
app.controller('AuthCtrl',
function ($scope, $location, Auth, User) {
if (Auth.signedIn()) {
$location.path('/');
}
$scope.$on('firebaseSimpleLogin:login', function(){
$location.path('/');
});
$scope.login = function(){
Auth.login($scope.user).then(function(){
$location.path('/');
}, function (error){
$scope.error = error.toString();
});
};
$scope.register = function () {
Auth.register($scope.user).then(function (authUser) {
Auth.login($scope.user);//cause creating user auto login
User.create(authUser, $scope.user.username);
console.log(authUser);
$location.path('/');
}, function (error){
$scope.error = error.toString();
});
};
});
Run Code Online (Sandbox Code Playgroud)
"用户"服务具有"创建"功能,该功能创建用户对象并应将对象信息存储在Firebase Forge中.如下所示,"users.$ save(username)"被称为"$ save"用户进入Firebase Forge.但是,当调用$ save方法时,我的Firebase Forge中没有任何反应.我回顾了最新的AngularFire规范,正如你在我的代码注释(//)中看到的那样,我尝试将$ asArray(),$ asObject()与我的"users"变量结合起来,但这样做无效.当我使用"users.$ add(username);" 而不是调用$ save方法,我的Firebase …
我正在创建一个简单的示例auth应用程序,Ionic 2和angularfire 2作为后端,当我尝试创建新用户时,它说:
EXCEPTION:错误:未捕获(在承诺中):错误:未为此Firebase启用指定的身份验证提供程序.
但是我已经在firebase控制台中启用了firebase身份验证:
app.ts
import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {HomePage} from './pages/home/home';
import { FIREBASE_PROVIDERS, defaultFirebase, firebaseAuthConfig, AuthProviders, AuthMethods } from 'angularfire2';
@App({
template: '<ion-nav [root]="rootPage"></ion-nav>',
providers: [
FIREBASE_PROVIDERS,
defaultFirebase('https://samplequizapp-50eb5.firebaseio.com'),
firebaseAuthConfig({
provider: AuthProviders.Password,
method: AuthMethods.Password
})
],
config: {} // http://ionicframework.com/docs/v2/api/config/Config/
})
export class MyApp {
rootPage: any = HomePage;
constructor(platform: Platform) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do …Run Code Online (Sandbox Code Playgroud) 我在 firebase 中有一个用户对象,我需要移动到同一棵树上的另一个子节点。
结构是这样的:
users -> male -> uid -> ......KVPs..objects...etc
-> female -> uid -> ......KVPs..objects...etc
Run Code Online (Sandbox Code Playgroud)
由于应用程序的性质,我需要将用户按性别分开。如果用户更改了他们的性别,我想将他们的所有详细信息移动到该选定的性别。
我尝试使用 AngularFire (firebaseObject),但是当我尝试在 firebase 中设置它时,由于对象中存在键,它会引发错误。我尝试使用 JSON.stringify、angular.toJSON 剥离键,但我没有任何运气!!
我想知道是否有更清洁或推荐的方法来做到这一点?感谢如果有人有任何指示或可以提供帮助。
非常感谢,诺埃尔
我正在使用角
对于我们的项目,我们需要对带有子域的 URL 提供多租户支持。
我们有类似于 Slack 的产品,我们的每个租户(客户)都有自己独立的数据库,因此我们希望他通过以下方式访问我们的产品:
client1.myproject.com
client2.myproject.com
client3.myproject.com
Run Code Online (Sandbox Code Playgroud)
等等。如何在 Angular 中做到这一点?我们知道角度路由只能改变路径而不是域。它甚至根本不支持吗?
谢谢!
PS:这是对我之前没有问过的问题的重新提问。
我正在 firestore auth 中动态创建用户,并添加了多种类型的声明,即管理员、讲师、助理。到目前为止admin: true,instructor: true根据我提供的登录凭据,我能够使用新创建的用户登录并获取 claim 属性为 true 。但是我无法[AuthGuard]在路由中正确设置,甚至没有登录我就可以使用 url 重定向到组件,这不应该发生。我对如何正确添加AuthGuard. 这是我的代码
auth-service.ts
import * as firebase from 'firebase/app';
import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
import { Injectable } from '@angular/core';
import { JwtHelperService } from '@auth0/angular-jwt';
import { Observable } from 'rxjs/Observable';
import { Router } from "@angular/router";
@Injectable()
export class AuthService {
public user: Observable<firebase.User>;
public userDetails: firebase.User = null;
constructor(private _firebaseAuth: AngularFireAuth, …Run Code Online (Sandbox Code Playgroud) 在Cloud Foreshore 的这份文档中提到,“请求一个集合 ID 列表,您需要为读取一个文档付费”。
现在我在我的项目中使用 AngularFire 和 Ionic3。我的要求是仅从具有 where 条件的集合中获取集合 ID。如果我执行以下操作,结果中的读取次数 = 文档数。
let snap = this.afs.collection('path').ref
.where('field', "==",'data').get();
snap.forEach(x => {
list.push(x.id);
});
Run Code Online (Sandbox Code Playgroud)
我无法使用getCollections()我在几个地方找到的方法作为解决方案。
如果您有解决方案,请告诉我。
我正在尝试根据文档 ID 查询文档,但无法使用
this.afs.collection<books>('books' , ref => ref.where( ref.id , 'in' , ['4L9uf4w5fqFXlU0uLbEM','bpXgEOmYqGor8uhUz2uq','tJFYPJcLMYNS8qnaUtMv'])).snapshotChanges().pipe(
map(actions => {
return actions.map( a => {
const data = a.payload.doc.data();
return {...data};
});
})
);
Run Code Online (Sandbox Code Playgroud)
afs 是 AngularFirestore 类型
不知道上面的代码是否正确。
我尝试了以下提到的解决方案: 通过将 ref.id 替换为 firebase.firestore.FieldPath.documentId() 来查询文档 ID的firestore 数据库,但出现错误:
'firebase' 指的是 UMD 全局,但当前文件是一个模块。
帮助我检索数据。
所以我通过 AngularFire 调用 firebase 函数,如下所示:
const response = await this.aFunctions.httpsCallable<void, ResponseType>('funcName')().toPromise();
Run Code Online (Sandbox Code Playgroud)
这在部署到 firebase(托管)时有效,但在本地环境中(使用ionic serve),它会引发此错误:
ERROR Error: Uncaught (in promise): FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad HTTP response code (404) was received when fetching the script. (messaging/failed-service-worker-registration).
FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker for scope ('http://localhost:8100/firebase-cloud-messaging-push-scope') with script ('http://localhost:8100/firebase-messaging-sw.js'): A bad …Run Code Online (Sandbox Code Playgroud) firebase angularfire ionic-framework google-cloud-functions angular
我按照本教程将 Angular Universal 部署到 firebase 函数并使用 Firebase 进行部署:https ://medium.com/@chris.duebbert/angular-9-universal-firebase-deploy-8d8d47244e1c
一切正常,直到我将 AngularFireModule 添加到我的 app.module.ts。然后,当我使用节点 12 运行“ng deploy”时,我在“ssr”函数的日志中收到以下错误:
提供的模块无法加载。您的代码中是否存在语法错误?详细的堆栈跟踪:ReferenceError: globalThis is not defined
当我尝试将本地节点版本设置为 10 时,我直接在终端中收到相同的错误。
显然,Firebase 使用 globalThis ,这需要节点版本 12(Angular 11 在 SSR @nguniversal/express-engine ReferenceError: globalThis is not defined 上运行)。我在 /functions/package.json 中添加了以下内容:
app.module.ts
"engines": {
"node": "12"
},
Run Code Online (Sandbox Code Playgroud)
我可以为节点版本输入任意数字,并且我的 SSR 功能仍在使用节点 10 进行部署,并且“globalThis”错误仍在继续。我正在使用 Firebase 的 Blaze 计划。这是我的 app.module.ts:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule.withServerTransition({ appId: 'serverApp' }),
AppRoutingModule,
NoopAnimationsModule,
FormsModule,
NgxTwitterTimelineModule,
AngularFireModule.initializeApp(config),
],
providers: [],
bootstrap: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 Firebase 实时数据库实施到一个有角度的项目中,但我陷入了第一步。导入 AngularFireModule 和 AngularFireDatabaseModule。它给了我以下错误:
Module '"@angular/fire"' has no exported member 'AngularFireModule'.ts(2305)
Run Code Online (Sandbox Code Playgroud)
Module '"@angular/fire/database"' has no exported member 'AngularFireDatabaseModule'.
Run Code Online (Sandbox Code Playgroud)
这是我导入它们的方式:
import {AngularFireModule } from '@angular/fire';
import {AngularFireDatabaseModule} from '@angular/fire/database'
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?我已经通过命令安装了@angular/fire
npm i firebase @angular/fire
Run Code Online (Sandbox Code Playgroud)
并且还安装了 firebase 工具。这是我目前安装的 Angular 软件包及其版本的列表:
Angular CLI: 12.2.2
Node: 14.17.4
Package Manager: npm 6.14.14
OS: win32 x64
Angular: 12.2.3
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.2
@angular-devkit/build-angular 12.2.2
@angular-devkit/core 12.2.2
@angular-devkit/schematics 12.2.2
@angular/cli 12.2.2
@angular/fire 7.0.0 …Run Code Online (Sandbox Code Playgroud) angularfire ×10
firebase ×9
angular ×5
angularjs ×2
typescript ×2
javascript ×1
node.js ×1
oauth ×1
subdomain ×1