import {AuthProviders, FirebaseAuthState, FirebaseAuth, AuthMethods} from "angularfire2";
import {Injectable} from "@angular/core";
import {Subject, BehaviorSubject} from "rxjs";
import {AuthInfo} from "./AuthInfo"; @Injectable()
export class AuthService { static UNKNOW_USER = new AuthInfo(null); private authState: FirebaseAuthState = null;
public authInfo$: BehaviorSubject<AuthInfo> = new BehaviorSubject<AuthInfo>(AuthService.UNKNOW_USER); constructor(public auth$: FirebaseAuth) {
auth$.subscribe((state: FirebaseAuthState) => {
this.authState = state;
});
} signUp(email, password){
return this.fromFirebaseAuthPromise(this.auth$.createUser(
{email, password}
));
} login(email, password) { return this.fromFirebaseAuthPromise(this.auth$.login({
email, password
},{
method: AuthMethods.Password,
provider: AuthProviders.Password
}));
} logout(){
this.auth$.logout();
this.authInfo$.next(AuthService.UNKNOW_USER);
} fromFirebaseAuthPromise(promise) {
const subject = new Subject<any>(); promise.then((res) => {
const uid = this.authState.uid;
const authInfo = new AuthInfo(uid);
this.authInfo$.next(authInfo);
subject.next(res);
subject.complete();
}, err => {
this.authInfo$.error(err);
subject.error(err);
subject.complete();
}); return subject.asObservable();
}
}

[AngularFire2] Signup and logout的更多相关文章

  1. [Node] Stateful Session Management for login, logout and signup

    Stateful session management: Store session which associate with user, and store in the menory on ser ...

  2. Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

    在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...

  3. linux笔记:关机重启命令shutdown,系统运行级别init,退出登录logout

    命令名称:shutdown功能:关机或重启用法:shutdown [选项] [时间]选项参数:-c 取消前一个关机命令-h 关机-r 重启时间格式:now 现在时:分 20:30其他:会正常关闭正在启 ...

  4. Spring Security(10)——退出登录logout

    要实现退出登录的功能我们需要在http元素下定义logout元素,这样Spring Security将自动为我们添加用于处理退出登录的过滤器LogoutFilter到FilterChain.当我们指定 ...

  5. login/logout切换

    1. 前端按钮 <img border="0" width="18" height="18" src="<%=base ...

  6. Login 和 Logout

    inux下Login和Logout详解                Login 是你用Linux系统工作时面对的第一个进程,这对于使用终端以及通过网络使用Linux都是正确的.但是login进程本身 ...

  7. laravel5.2之logout注销账号无效

    问题描述:laravel5.2的框架,使用框架auth用户认证后,进行账号注销退出的时候,无法实现. 只有清除浏览器缓存,才能实现账号退出. 解决办法: 改变路由 Route::get('auth/l ...

  8. Spring Security 入门(1-3-3)Spring Security - logout 退出登录

    要实现退出登录的功能我们需要在 http 元素下定义 logout 元素,这样 Spring Security 将自动为我们添加用于处理退出登录的过滤器 LogoutFilter 到 FilterCh ...

  9. spring-security doc logout

    18.5.3 Logging Out Adding CSRF will update the LogoutFilter to only use HTTP POST. This ensures that ...

随机推荐

  1. sql%rowcount 返回影响行数

    oracle中.返回影响行数是:If sql%rowcount 举例: update ut_calenderStatus t set t.calenderstatus=pi_flg, t.m=pi_M ...

  2. Qt之输出控制

    简述 在Qt项目开发过程中,往往需要对程序的一些信息进行控制,比如:打印日志.调试信息等,便于我们后期查找.跟踪及定位问题. 下面,我们来分享下常用的几种方式. 简述 示例代码 应用程序输出 控制台输 ...

  3. Android 基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器aaa

    MDPlayer万能播放器 MDPlayer,基于ijkplayer+Rxjava+Rxandroid+Retrofit2.0+MVP+Material Design的android万能播放器,可以播 ...

  4. Angularjs:实现全选

    html: <div class="input-group"> <span class="input-group-addon" style=& ...

  5. 配置spotlight连接linux服务器

    本文转自(https://blog.csdn.net/qq_31391261/article/details/79429098) 一.配置spotlight连接linux服务器 1.以管理员身份运行软 ...

  6. R语言-方差分析

    方差分析指的是不同变量之间互相影响从而导致结果的变化 1.单因素方差分析: 案例:50名患者接受降低胆固醇治疗的药物,其中三种治疗条件使用药物相同(20mg一天一次,10mg一天两次,5mg一天四次) ...

  7. 1.2 Use Cases中 Event Sourcing官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Event Sourcing 事件采集 Event sourcing is a st ...

  8. Js里面的arguments

    了解这个对象之前先来认识一下javascript的一些功能: 其实Javascript并没有重载函数的功能,但是Arguments对象能够模拟重载.Javascrip中国每个函数都会有一个Argume ...

  9. HDU 1166 敌兵布阵 树状数组||线段树

    http://acm.hdu.edu.cn/showproblem.php?pid=1166 题目大意: 给定n个数的区间N<=50000,还有Q个询问(Q<=40000)求区间和. 每个 ...

  10. UVA 11796 - Dog Distance 向量的应用

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...