如何在离子2中实现登录流程?

Mon*_*key 7 ionic2

所以我试图从离子1开始使用离子2,并且需要一些关于如何在我的项目中设置身份验证的指导.具体来说,我正在使用firebase和angularfire2.

作为一般方法,我应该:

一个.检查app.ts上的session/localStorage,如果未经身份验证,请将rootPage设置为登录?如果我将用户注销并将导航根页面设置回登录,则使用此方法,选项卡将显示在底部.

湾 创建登录页面作为模式,删除显示在底部的选项卡的问题,但我不确定是否应该从app.ts启动模式,因为我不确定应用程序本身是否具有根视图我应该参考.

另外,我应该将auth登录和注销设置为服务并重构,而不是将其放在登录页面和配置文件控制器中的注销按钮中吗?

到目前为止,这是我使用方法A的逻辑:

app.ts

export class MyApp {
  rootPage: any;
  local: Storage = new Storage(LocalStorage);
  constructor(platform: Platform) {
    this.local.get('user').then(user => {
      if (user) {
        this.rootPage = TabsPage;
      } else {
        this.rootPage = LoginPage;
      }
    });

    platform.ready().then(() => {
      StatusBar.styleDefault();
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

在myProfile.ts中

  logout() {
    this.local.remove('user');
    this.user = null;
    let modal = Modal.create(LoginPage);
    this.nav.present(modal); //should I set the rootPage instead?  if so how do I remove the tabBar or set the rootpage of the containing app root page
  }
Run Code Online (Sandbox Code Playgroud)

Mic*_*aud 0

下面是一个 ionic 登录流程的示例,其中 jwt 存储在本地存储中:

https://github.com/RedFroggy/ionic2-nfc-app/tree/master/app/pages/login