7

My Firebase/Ionic 2アプリはブラウザ(ionic serve)とローカルのAndroidデバイス(ionic run android)で完全に動作します。このアプリはFirebaseデータベースと認証機能を使用します。Ionic 2 AppのFirebase認証ネットワークエラー

アプリはiOSデバイスでも完全に動作します。

Androidでベータ版テストを行うためにGoogle Playに公開すると、auth loginメソッドは常に失敗します。「ネットワークエラー(タイムアウト、接続が中断されたか、到達不能なホストなど)が発生しました。しかし、Firebaseのデータベースメソッドは正常に動作しています。 Firebaseのメール/パスワードプロバイダのみを使用しています。

私はこの問題に似ていると私は見つけることができるすべての記事を読んで、すべてのソリューションを試してみました。私はすべてのコンポーネントの最新バージョンにアップグレードしました。

cordova-plugin-whitelist pluginがインストールされています。これは、新しいIonic 2プロジェクトにデフォルトでインストールされます。私の理解は、Firebaseをブロックしていない以下のセキュリティ設定です。

index.htmlを

<meta http-equiv="Content-Security-Policy" content="font-src * data:; img-src * data:; default-src * 'unsafe-eval' 'unsafe-inline'; script-src * 'unsafe-eval' 'unsafe-inline'"> 

config.xmlの

<access origin="*"/> 
<allow-intent href="http://*/*"/> 
<allow-intent href="https://*/*"/> 
<allow-navigation href="*"/> 

マイサービス

public login(email: string, password: string): Observable<any> { 
    return Observable.fromPromise(
     <Promise<any>>firebase.auth().signInWithEmailAndPassword(email, password) 
    ); 
} 

マイフォーム

this.authService.login(this.loginForm.value.email, this.loginForm.value.password) 
     .subscribe(() => { 
      // Do something! 
     }, error => { 
      // A network error has occurred! 
     }); 

バージョン情報

Cordova CLI: 6.5.0 
Ionic Framework Version: 2.2.0 
Ionic CLI Version: 2.2.1 
Ionic App Lib Version: 2.2.0 
Ionic App Scripts Version: 1.1.4 
Node Version: v7.2.1 

In package.json: "firebase": "^3.7.1" 
In config.xml: <plugin name="cordova-plugin-whitelist" spec="1.3.1"/> 

答えて

2

私はローカルに構築し、以下のセキュリティ設定を指定することでこの問題を回避することができました。

生産に適した設定が見つからないことに注意してください。私はホワイトリストにドメインがないと思う。

私はionic.ioを使用して.apkを生成していましたが、何らかの理由で問題のあるビルドを生成しました。奇妙な点は、Firebase認証以外のすべてが機能していることです。

index.htmlを

<meta http-equiv="Content-Security-Policy" content="default-src * data: gap://ready https://ssl.gstatic.com file://* ws://* wss://*; img-src * data:; font-src * data:; script-src * https://*.google-analytics.com https://*.googleapis.com https://*.firebaseio.com 'unsafe-eval' 'unsafe-inline';"> 

default-src *script-src *の使用に注意してください。これらのいずれかを「自己」に変更すると、エラーが発生します。

<access origin="*"/> 
    <access origin="https://*.google-analytics.com"/> 
    <access origin="https://*.googleapis.com"/> 
    <access origin="https://*.firebaseio.com"/> 
    <allow-navigation href="*"/> 
    <allow-navigation href="http://ionic.local/*"/> 
    <allow-intent href="http://*/*"/> 
    <allow-intent href="https://*/*"/> 
    <allow-intent href="tel:*"/> 
    <allow-intent href="sms:*"/> 
    <allow-intent href="mailto:*"/> 
    <allow-intent href="geo:*"/> 

config.xmlが<access origin="*"/>の使用に注意してください。この行を削除すると、エラーが発生します。

興味深いことに、<access origin="*"/>行を削除してローカルにビルドすると、ionic.ioでビルドするときと同じエラーが発生します。

+0

問題がコードに関連していない可能性があります。「認証」セクションの「ログイン方法」サブセクションにチェックを入れたい場合は、 – user1928596

関連する問題