【问题标题】:Quickstart Auth0 with Ionic2使用 Ionic2 快速入门 Auth0
【发布时间】:2016-10-02 05:37:43
【问题描述】:

我是 ionic2(和 angular2)的新手,我尝试在我的第一个应用程序中实现 auth0。 所以我跟着这个:https://auth0.com/docs/quickstart/hybrid/ionic2/no-api

我从 ionic2 网站上的“开始”开始,一切正常。 然后,我按照 auth0 快速入门中的所有步骤进行操作,但是当我执行“离子服务”时,我收到此错误:

0     883034   error    Uncaught Invalid provider - only instances of Provider and Type are allowed, got: [object Object], http://localhost:8100/build/js/app.bundle.js, Line: 24470

我认为问题出在 app.ts 中,在 @App 提供者中:

import {App, Platform} from 'ionic-angular';
import {StatusBar} from 'ionic-native';
import {TabsPage} from './pages/tabs/tabs';
import {provide} from 'angular2/core';
import {Http} from 'angular2/http'
import {AuthHttp, AuthConfig} from 'angular2-jwt';
import {AuthService} from './services/auth/auth';
import {Type} from 'angular2/core';


@App({
    template: '<ion-nav [root]="rootPage"></ion-nav>',
    config: {},
    providers: [
        provide(AuthHttp, {
            useFactory: (http) => {
                return new AuthHttp(new AuthConfig(), http);
            },
            deps: [Http]
        }),
        AuthService
    ],
 })
export class MyApp {
rootPage: any = TabsPage;

constructor(platform: Platform) {
    platform.ready().then(() => {
        StatusBar.styleDefault();
        // When the app starts up, there might be a valid
        // token in local storage. If there is, we should
        // schedule an initial token refresh for when the
        // token expires
        this.auth.startupTokenRefresh();

    });
}

}

谢谢帮助我!

【问题讨论】:

  • 我有同样的问题,有什么帮助吗? :S

标签: angular ionic2 auth0


【解决方案1】:

检查你的package.json,我删除的时候出现这个错误:

"angular2": "2.0.0-beta.15",

在文件依赖项中。 希望它有所帮助,但它可能是其他的东西。

【讨论】:

    【解决方案2】:

    您正在使用 @App 装饰器。这意味着您使用的是 Ionic 2 的旧 Beta。请更新到最新版本并以“新”方式引导它:

    ionicBootstrap(MyApp, [
      provide(AuthHttp, {
        useFactory: (http) => {
          return new AuthHttp(new AuthConfig({noJwtError: true}), http);
        },
        deps: [Http]
      })],
      {
        tabbarPlacement: 'bottom'
      }
    );
    

    它应该这样工作!

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 2017-02-17
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 2014-11-12
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      相关资源
      最近更新 更多