简体   繁体   中英

Firebase signUpWithEmailAndPassword using Ionic

I am using the latest version of Ionic (v1.3.1) and Firebase (v3.1.0). I'm trying to do firebase user authentication using the following method:

firebase.auth().signInWithEmailAndPassword(email, password)

Whilst this method works perfectly when ionic is running in a web browser, when the ionic app is run natively on Android, it throws an error, specifically:

'A network error (such as timeout, interrupted connection or unreachable host) has occurred.'

I have made sure the app's config.xml allows access to all URLs so it doesn't appear to be an issue with Ionic.

Looking online, it seems that Firebase is possibly blocking the app's browser because it doesn't recognise the app's domain (domains for authentication appear to be whitelisted in the 'OAuth redirect domains' part of the authentication section in the Firebase dashboard).

However, there is not way to identify what an Ionic app's domain is (it certainly isn't 'localhost' or 127.0.0.1)

So, my question is: does Firebase signInWithEmailAndPassword(email, password) actually work with Ionic and other web-wrapper platforms, or is this currently unsupported?

Make sure you are setting the correct Content-Security-Policy too. Something along:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *;script-src 'self' https://* 'unsafe-inline' 'unsafe-eval'; connect-src 'self' https://* 'unsafe-inline' 'unsafe-eval'; ">

Many thanks for the responses. For those interested in the solution to this problem, it did not reside with Firebase. Rather, newer versions of Cordova and Ionic sometimes throw http 404 errors when the app tries to make network requests.

In order to solve these 404 errors, the app needs the Cordova WhiteList plugin added:

http://docs.ionic.io/docs/cordova-whitelist

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM