我正在尝试将a firebase.Promise转换为Observable使用angular-cli生成的项目.
在这里它说,firebase.Promise可以兼容Native Promise和Promise/A+实施.
但是当我尝试使用Observable.fromPromise()rxjs 的方法时出现错误.
Argument of type 'firebase.Promise<any>' is not assignable to parameter of type 'Promise<any>'.
Types of property 'then' are incompatible.
Type '(onResolve?: (a: any) => any, onReject?: (a: Error) => any) => Promise<any>' is not assignable to type '{ <TResult1, TResult2>(onfulfilled: (value:
any) => TResult1 | PromiseLike<TResult1>, onrejected:...'.
Type 'firebase.Promise<any>' is not assignable to type 'Promise<any>'.
Run Code Online (Sandbox Code Playgroud)
它实际上工作,但有错误令人讨厌,任何关于如何以干净的方式避免这个错误的想法?
谢谢.
如何在Angular2/TypeScript/AngularFire2中实例化Firebase云消息传递?
这里针对JavaScript进行了描述:https: //firebase.google.com/docs/cloud-messaging/js/client
firebase typescript firebase-cloud-messaging angularfire2 angular
我想检查我的adminauthguard,如果用户设置了adminflag(在Firebase中使用angularfire2)
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> | boolean {
return this.loginservice.af.auth.map((auth) => {
if(auth == null) {
return false;
} else {
this.membersservice.get(auth.uid).subscribe(users => {
if(users.admin == true) {
return true;
} else {
return false;
}
})
}
});
Run Code Online (Sandbox Code Playgroud)
如何在可观察的内部解析observable?
firebase typescript firebase-authentication angularfire2 angular
我有一个使用angularfire2的工作身份验证,我只是想知道是否有另一种方法来检查用户最近登录后是否验证用户是否在服务器上?我这样做是这样的
isAuthenticated():boolean{
this.af.auth.subscribe(data => {
if(data ){
// User is authenticated
return true;
}
});
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏
编辑1:
我决定仍然使用原始代码来检查用户是否最近登录.当你在应用程序启动时没有检查用户时,@ cartant建议的是足够的,因为它可能会返回null,如firebase官方所述文档.我在这里使用它的方式是我有菜单项只应该向经过身份验证的用户显示,并且使用firebase.auth().currentUser将始终在页面的初始加载时返回null.
这个函数由构造函数调用.有人可以向我深入解释它的作用吗?
initializeItems(){
this.travelList$ = this.plsdala.getTravelList()
.snapshotChanges()
.map(
changes => {
return changes.map(c=>({
key: c.payload.key, ...c.payload.val()
})).slice().reverse();
//to reverse order
});
}
Run Code Online (Sandbox Code Playgroud) 我已经使用 firebase 为身份验证服务中的 angular 应用程序设置了身份验证,并且我正在尝试确保成功登录后会话状态的持久性。
我已经看到默认情况下 firebase 应该具有状态持久性,但是应用程序中的当前登录仅持续到页面刷新,之后再次需要登录,这似乎不正确。
我知道我必须使用 statePersistence 方法,如文档中所示,但这并没有说明如何在 angular 2+ 应用程序中实际实现登录/身份验证服务。
如何在以下身份验证服务中实现会话 statePersistence?:
auth.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import * as firebase from 'firebase/app';
import { AngularFireAuth } from 'angularfire2/auth';
@Injectable()
export class AuthService {
private user: Observable<firebase.User>;
isAuthenticated: boolean = false;
constructor(private firebaseAuth: AngularFireAuth, private router: Router) {
this.user = firebaseAuth.authState;
}
signIn(email: string, password: string) {
this.firebaseAuth
.auth
.signInWithEmailAndPassword(email, password)
.then(value …Run Code Online (Sandbox Code Playgroud) authentication firebase firebase-authentication angularfire2 angular
我知道Angular 6中必须创建单例服务的方式已经发生了一些变化。我有一个身份验证服务,需要为访问它的每个组件构造一次。我将提供程序设置为服务的根目录:
@Injectable({
providedIn: 'root'
})Run Code Online (Sandbox Code Playgroud)
在我的app.module.ts文件中,我将AuthService设置为NgModule中的提供程序之一。但是,每当我在使用Auth服务的不同组件之间路由时,它都会创建Auth Service的新实例(从第一次调用它时清除数据)。如何确保仅将Auth Service实例化一次,然后在不同组件之间访问该实例?
我想制作一个war文件来在apache tomcat服务器中部署angular2项目。我做了一个 Maven 项目并在其中插入了 angular2 项目。然后我使用angular-cli在maven项目的src/main中创建了webapp文件夹(而不是angular2项目中的dist文件夹)。当我运行 apache 服务器时,它显示以下错误。
从http://localhost:8080/app/app.module.js加载http://localhost:8080/vendor/angularfire2/angularfire2.js为“angularfire2”时出错;区域: ; 任务: Promise.then ;值:错误:错误:XHR 错误(404 未找到)正在加载http://localhost:8080/traceur (...) null
这看起来麻烦的依赖是angularfire2。怎么算我们的?顺便说一句,我使用 angular2 rc-5。
我正在尝试使用 firebase 的 AngularFire2 进行 Facebook 身份验证。我遵循与本教程完全相同的步骤github.com/angular/angularfire2/blob/master/docs/Auth-with-Ionic2.md
但由于某种原因,这行不通。它给了我提供者页面上的许多错误。这是我的代码。
import { Injectable } from '@angular/core';
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AuthService {
private authState: Observable<firebase.User>;
private currentUser: firebase.User;
constructor(public http: Http, public afAuth: AngularFireAuth) {
console.log('Hello AuthService Provider');
this.authState = afAuth.authState; //First error here.
afAuth.subscribe((user: firebase.User) => { //second here …Run Code Online (Sandbox Code Playgroud) angularjs firebase firebase-authentication ionic2 angularfire2
要允许访问管理路由,我必须检查两件事:
管理卫士
import {ActivatedRouteSnapshot, CanActivate, Router,
RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/Observable';
import {AngularFireAuth} from 'angularfire2/auth';
import {Injectable} from '@angular/core';
import {DbActionsService} from '../services/db-actions.service';
import {AuthService} from '../services/auth.service';
import 'rxjs/add/operator/map';
@Injectable()
export class AdminGuard implements CanActivate {
constructor(private afAuth: AngularFireAuth, private router: Router, private dbAction: DbActionsService, private authService : AuthService) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
if (this.afAuth.auth.currentUser) {
return this.dbAction.getUserProfileData(this.afAuth.auth.currentUser.email).map((user) => {
if (user[0].admin) {
return true;
} else {
this.router.navigate(['/']); …Run Code Online (Sandbox Code Playgroud) angularfire2 ×10
angular ×9
firebase ×9
typescript ×3
angular5 ×1
angular6 ×1
angularjs ×1
ionic2 ×1
maven ×1
rxjs ×1