Our app uses the Firestore and Firebase Functions. To save an order, we call a https callable Firebase Function like this:
try {
const setMealplanOrder = fn.httpsCallable("setMealplanOrder");
await setMealplanOrder(newOrder);
return true;
} catch (error) {
console.log("🚀 ~ file: saveOrder.tsx ~ line 158 ~ save ~ error", error)
Sentry.captureMessage("Error saving order, possibly on Android?" + error);
}
It works and has worked on all devices, until a few days old Samsung update to Android 11 and Samsung internet 14. Now, the XHR request from await setMealplanOrder(newOrder) is just stuck. The console is empty, with no errors.
Any idea what could it be? Or how to debug this?
Additional notes:
Interestingly, when I connect the phone to the app on a localhost, it works perfectly.
When I try to fire the same request from a new clean app, it works. So the issue is probably caused in a combination with something else in the app.
Solved: Firebase version issue! The issue was in firebase-messaging-sw.js Service Worker, which we use for Firebase Cloud Messaging (push-notification). The version of the service worker was outdated.
// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/7.17.2/firebase-app.js')
importScripts('https://www.gstatic.com/firebasejs/7.17.2/firebase-messaging.js')
...
After updating both npm i firebase#latest and changing the version in the importScripts to 8.4.3, it works as it should.
Related
I have to improve existing Ionic app using firebase as auth method for users login.
For my purpose i cannot touch existing list of previously registered users in production firebase app, I have to create new list locally using firebase emulator.
After adding and setup local auth & DB emulator extensions, I have added this into app.module.ts:
if (window.location.hostname === 'localhost') {
firebase.auth().useEmulator('http://localhost:9099');
}
After continuing with adding new UI and logical features, using a web browser to test my work, I switch to the Android platform. After running the app and executing
firebase.auth().signInWithEmailAndPassword(email, password);
I got the following error:
{
"code": "auth/network-request-failed",
"message": "A network error (such as timeout, interrupted connection, or unreachable host) has occurred."
}
It worked fine in the browser, but not on real device.
Whereas on Android device
window.location.hostname === 'localhost
this will be executed
firebase.auth().useEmulator('http://localhost:9099');
so Firebase searching auth service on device on port 9099, that not exists, and produce such error.
To fix this just run in terminal
adb reverse tcp:9099 tcp:9099
🟢 Fixed server-side
Note: this was a server side bug and for now seems to be solved. Our mobile app code remains unchanged.
I have to use HMS Push Services in order to make my RN App working for Huawei EMUI devices: HMS Core.
I followed all the required steps to install and configure HMS both on the server and on the mobile App.
However... I noticed a weird behavior. I use a button on the web page to send a Push Notification from the server to the Mobile App. I ensured that Push Kit is enabled on my Huawei ID and the Push Device Token is the correct one.
Sometimes the notification is sent and sometimes no. I tried all the day to find the cause, but for now it seems to be completely aleatory, at least until the cause will be not found.
Please note that in the code below the mc.send() goes every times into the .then() and never raised the .catch().
Sometimes I get: OK {"code":"80000000","msg":"Success","requestId":"161832746491754926000107"} and the notification is actually received from the Mobile App (all fine!).
Sometimes (and quite often): OK {"code":"80300002","msg":"No permission to send message to these tmIDs","requestId":"161832753512250325000107"}
Lastly, I am getting continuously: OK {"code":"80000000","msg":"Success","requestId":"161832795126307445060711"} but... the App does not receives actually the notification.
I tried to restart server, keep the App in the three various States (closed, foreground, background), but nothing helped me to find the problem.
This is the last version of the code I use to send the notification (I changed it many times):
function sendPushNotificationHMS(pushDeviceToken, data, attempt){
hcm.init({
appId: configHMS.AppId,
appSecret: configHMS.AppSecret,
authUrl: configHMS.AuthUrl,
pushUrl: configHMS.PushUrl
});
let mc = hcm.messaging().messaging;
let androidConfig = {
collapse_key: -1,
urgency:"HIGH",
ttl: "10000s",
bi_tag: "the_sample_bi_tag_for_receipt_service",
}
let message = {
data: JSON.stringify(data),
android: androidConfig,
token: new Array(pushDeviceToken)
};
mc.send(message, true).then(data => {
console.log('OK ', data);
}).catch(err => {
console.log('ERR ', err);
});
}
Please refer to this documentation:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/commonerror-0000001059816656
and see if one of the solution under 80300002 is correct. Since you have checked if your IDs are correct, please check the tips under 2, 4, 6, and 7.
I am currently making a call to my server to make a change in the Datastore and listening for another change to it. I do not receive any new changes from the DB despite the database being changed correctly on the backend.
I recently upgraded amplify from 1.4.2 to 1.6.8 and this is when the issue started to show up.
Amplify.DataStore.observe(Profile::class.java,
{ observationCancelable ->
//ERROR
},
{ changedItem ->
when (changedItem.item().state) {
//DO Business logic
}
},
{ exception ->
//ERROR
},
{
}
)
When I query the datastore I am getting outdated results that are not the same as the data on DynamoDB. Is there any way to figure out why the local datastore is not being updated? Could it be an issue with the configuration with the server? Or is there some setup step that I have missed?
Edit: Added some extra details below
So a few more details I wanted to add to this that seem way more relevant as well as updates based on my research. I am switching between endpoints(dev to testing environments). It would seem that the dev environment is working fine with the application, using the datastore correctly and doing the proper AppSync. But in the new testing environment, when the app starts, it gets the latest version of the datastore but it fails to do any AppSync despite being able to make changes to the backend.
Here is an error I am getting when the app attempts to subscribe to the Profile object in the back end
amplify:aws-datastore: Unauthorized failure for ON_CREATE Profile
amplify:aws-datastore: Releasing latch due to an error: Subscription error for Profile: [GraphQLResponse.Error{message='Not Authorized to access onCreateProfile on type Subscription', locations='null', path='null', extensions='{errorType=Unauthorized}'}]
Is there some config file that I should be looking at to compare with to make sure that the endpoints match or some access key that the app needs?
I'm using Ionic with React and #codetrix-studio's capacitor-google-auth plugin to enable google auth. The processed idToken has different lengths when comparing Web to Android environments.
When running in the web browser I'm getting 1224 chars and everything works just fine. But when running android I'm only getting 1122 chars. Also I'm not getting anything out of the accessToken.
Can anyone provide some hits on how to solve this?
I'm getting the token like so:
async signIn(): Promise<void> {
const result: any = await Plugins.GoogleAuth.signIn();
if (result) {
let token = result.authentication.idToken;
this.setToastMsg(token.length + "");
}
}
This is triggered from a simple button:
<IonButton onClick={() => this.signIn2()} >Login with Google</IonButton>
Turns out the token provided by google for the android api is actually smaller. So everything is ok.
I'm building a chat application for Android using a Node.js server..
When a user wants to open a new Topic/chat group, few things need to be done:
1. Create the Topic using Amazon's (AWS) SNS SDK.
2. Subscribe each one of the requested users to this Topic, using their AWS Endpoint ARN.
My question is on the Node.js AWS SDK, but corresponds to the AWS Android API as well as they currently work the same in this matter.
Question 1:
How do I subscribe multiple Endpoint ARNs in one call?
Currently I have to wait after each "subscription request" to make sure it is successful before I submit the next one. It takes too much time and effort.
Question 2:
In case a user wants to unsubscribe from the entire app, I delete his/her Endpoint from AWS-SNS.
BUT, their subscriptions to the various topics remain! So effectively, they still receive all the data/messages (and there is no app to receive it of course).
Please let me know if any code is needed.
* I thought maybe I would just put a json'd List with all the ARNs, but it did not work.
Currently AWS SDK does not accept the array of Arns.
AWS-SDK/sns.subscribe
The possible solution is to use a bulk array of requests but this action is throttled at 100 transactions per second (TPS) according to the AWS documentation.
Here is an example of Node.js API calls.
const subscribe = async (TopicArn, arns) => {
try {
const promises = []
arns.forEach((Endpoint) => {
promises.push(sns.subscribe({
Protocol: 'application',
TopicArn,
Endpoint,
}).promise())
})
await Promise.all(promises)
} catch (e) {
console.error(e)
}
}