Firebase email authentication in Ionic 2 failing in device - ionic-framework

I have tried the firebase email authentication with an ionic 2 app. The authentication is working in the browser with 'ionic serve' but not on the device.
I can create new users and login in the browser and nothing is working on the device.
I have an auth-data provider with the following function:
loginUser(email: string, password: string): any {
return this.fireAuth.signInWithEmailAndPassword(email, password);
}
And calling this function from login.ts
loginUser() {
//Call to AuthData service to login the user
this.authData.loginUser(this.loginForm.value.email, this.loginForm.value.password).then( authData => {
//User is authenticated and navigates to homePage
this.nav.setRoot(HomePage);
})
}
I'm getting this alert on device:
"A network error (such as timeout, interrupted connection or unreachable host) has occurred."
Any idea on what's going on?

Please install cordova whitelist plugin by
cordova plugin add cordova-plugin-whitelist
and add the following line to src/config.xml
<allow-intent href="https://*.firebaseio.com"/>

Related

Appwrite sms authentication connection times out

I want to enable phone authentication on my flutter app with appwrite. I followed the official guidelines, changed the .env variables of appwrite and used docker compose up -d to restart appwrite with the correct credentials. As SMS provider I am using text-magic therefore my .env file has the following configurations for sms:
_APP_SMS_PROVIDER=sms://[USERNAME]:[API-KEY]#text-magic
_APP_SMS_FROM=+123456789
Username and API-Key come from textmagic
Additionallly I've created a simple method to create a phone Session.
createPhoneSession(String phonenumber) async {
try {
Client client = Client();
client
.setEndpoint(AppConstants.endpointId)
.setProject(AppConstants.projectId);
Account account = Account(client);
var token = await account.createPhoneSession(userId: ID.unique(), phone: phonenumber);
print(token.$id);
} catch (error) {
print(error);
}
}
The exception I get is the following:
I/flutter ( 5195): AppwriteException: null, Connection timed out (0)
Any suggestions why it keeps timing out? Thank you for your help in advance!
As you mentioned, the endpoint was incorrect. When developing locally, you can't use localhost for the endpoint because the mobile device will try to connect to itself rather than Appwrite. Instead of localhost, you can use your LAN IP.

Firebase auth emulator's console "sign in as" link, for passwordless sign in testing, is not resulting in successful auth

When using firebase auth emulator, the console where firebase emulators:start is running, will output a link to emulate sign in.
My app is being built in Flutter. The following code creates the sign in link that is output in the emulator console.
final ActionCodeSettings acs = ActionCodeSettings(
url: 'https://example.com',
dynamicLinkDomain: 'mydomain.page.link',
handleCodeInApp: true,
iOSBundleId: kIosBundledId,
androidPackageName: kAndroidPackageName,
androidInstallApp: true,
androidMinimumVersion: '24',
);
await _firebaseAuth
.sendSignInLinkToEmail(
email: email,
actionCodeSettings: acs,
)
.catchError((onError) {
throw AuthException('Error sending email verification $onError');
}).then((value) {
debugPrint('Successfully sent email verification.');
});
Code above outputs links like the following where the action?mode=signIn:
http://localhost:9099/emulator/action?mode=signIn&lang=en&oobCode=lkjlkjklj&apiKey=fake-api-key&continueUrl=https%3A%2F%2Fmydomain.page.link%2FezHe
Pasting the link into my browser where the auth emulator is running at http://localhost:9099 I'm expecting to see something like this.
{
"authEmulator": {
"success": "The email has been successfully verified and you are signed in.",
"email": "customer#example.com"
}
}
Rather than the expected "success..." output, the continueUrl link, which is the short url configured in my Dynamic Links, is called and this short url then redirects to the configured deep link url for the dynamic link, which lands me on my desktop website. No auth emulator results are displayed.
If I remove the continueUrl parameter I can see the auth emulator output like below, so I know the auth emulator is evaluating the sign in as link. I can't find any docs on how to trigger the auth emulator for passwordless sign in auth testing.
{
"authEmulator": {
"error": "Missing continueUrl query parameter",
"instructions": "To sign in, append &continueUrl=YOUR_APP_URL to the link."
}
}
Am I missing an auth emulator parameter that should be part of the url to trigger passwordless sign in as auth?

Http request working on ionic serve but doesn't work on "ionic cordova run android --device"

I am using Ionic native http to make server requests. The server is hosted on aws and the apis are up and running (verified by postman).
When i do ionic serve the requests go through and work but when i try to run it on device it doesnt work. On inspection i get "net::ERR_CLEARTEXT_NOT_PERMITTED" and post is sent as OPTIONS
ERROR HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: "http://18.220.143.133/api/login", ok: false, …}
already tried adding to config.xml
login(user: User): Observable<AuthResponse> {
return this.httpClient.post('http://18.220.143.133/api/login', user, {
headers: new HttpHeaders().set('Content-Type', 'application/json'),
}).pipe(
tap(async (res: AuthResponse) => {
if (res.success == true) {
await this.storage.set('user',res.user);
await this.storage.set('ACCESS_TOKEN', res.token);
this.authSubject.next(true);
}
})
);
}
I expect http requests to go through from mobile devices as well.
The same happened to me, until in the config.xml file I added:
<preference name = "android-targetSdkVersion" value = "27" />
It has to do with your CORS for the API call. This may help. Also, since you're using Angular HTTP requests, check here HTTP request from angular will send with method OPTIONS instead of POST.

Google Auth for Ionic App

i'm using cordova-plugin-googleplus for authentication with google accounts in my Ionic app.
I've done all the steps listed in docs, but it stills doesn't working. I've got the diabolic 12501 error.
I have the credentials and i'm calling the authentication method using:
vm.loginWithGoogle = () => {
console.log('Login with google', window.plugins.googleplus);
window.plugins.googleplus.login(
{webClientId:'my-credentials'},
success => console.log('success', success),
error => console.log('error', error)
);
}
Somebody passed through this before?
just now i'm facing this issue. solved by
on "ionic plugin add", reverse your key you got from google console
sign your app with key generated from keytool that you used for google console
regards,

Cors request Rejected

I am facing an error and I don't known what to do. Whenever I try to save user to my ionic user service using the following code:
Ionic.io();
var user = Ionic.User.current();
if (user.id) {
user.set('name', username);
//user.set('image',image_name);
}
user.save();
and then I get this error:
Ionic User: Error: CORS request rejected
XMLHttpRequest cannot load https://api.ionic.io/auth/users/null.
Response for preflight has invalid HTTP status code 404
OPTIONS https:// api .ionic .io /auth /users /null
[cors request rejected][1]
[coding][2]
Ionic has a cordova plugin that sorts out all CORS issues called "cordova-plugin-whitelist". When you test through the browser, the Cordova plugins are not active, hence it's not sorting out your issues. Only when you deploy your app to android/ios/windows will the Cordova plugins work.
Rather get "Allow-Control-Allow-Origin" chrome plugin to allow you to make requests if you want to test on your browser.