geosolutions-it / smb-portal

SaveMyByke portal
https://waffle.io/geosolutions-it/smb-portal
1 stars 3 forks source link

Problem with Firebase Registration #206

Closed pragmaware closed 3 years ago

pragmaware commented 5 years ago

There seems to be an issue with the "my-devices" POST api. See the android log below. The same thing happens from iOS (last time I checked).

The client sends the POST with the following json as body:

{"device_id":"6f5f20379d1e2c59","registration_id":"fR4V1kYjzeQ:APA91bHqTcTNuxXsS1VMZkbOf8_IYJ0CgRQkJ7huFB-X3xSqTjAEyrYWTSWT1BlpOVtoP_LvWMImzWTe-xSNJC4EFtcaPTLSdGzlyJctNjrR0i_agyooAArP02Tc6m66MDVHAvQeW_1i","type":"android"}

Server says 400 Bad Request

{"registration_id":["This field must be unique."]}


LOG:

2019-09-18 13:22:11.895 14049-14219/it.geosolutions.savemybike D/RetrofitClient: request

Sending POST to https://dev.savemybike.geo-solutions.it/api/my-devices/
{"device_id":"6f5f20379d1e2c59","registration_id":"fR4V1kYjzeQ:APA91bHqTcTNuxXsS1VMZkbOf8_IYJ0CgRQkJ7huFB-X3xSqTjAEyrYWTSWT1BlpOVtoP_LvWMImzWTe-xSNJC4EFtcaPTLSdGzlyJctNjrR0i_agyooAArP02Tc6m66MDVHAvQeW_1i","type":"android"}

[...]

2019-09-18 13:22:12.307 14049-14219/it.geosolutions.savemybike D/RetrofitClient: response Received response for https://dev.savemybike.geo-solutions.it/api/my-devices/ in 410.0ms Server: nginx/1.14.0 (Ubuntu) Date: Wed, 18 Sep 2019 11:22:12 GMT Content-Type: application/json Content-Length: 50 Connection: keep-alive Vary: Accept, Accept-Language, Cookie Allow: GET, POST, HEAD, OPTIONS X-Frame-Options: SAMEORIGIN Content-Language: it Set-Cookie: sessionid=2a37spguwtn2e7cqgpfxhqiig4byz0xl; expires=Wed, 02-Oct-2019 11:22:12 GMT; HttpOnly; Max-Age=1209600; Path=/

{"registration_id":["This field must be unique."]}

2019-09-18 13:22:12.313 14049-14049/it.geosolutions.savemybike E/SaveMyBikeActivity: Can not update firebase token for this Device java.lang.Throwable: 400 Bad Request at it.geosolutions.savemybike.data.server.RetrofitClient$2.onResponse(RetrofitClient.java:231) ...

giohappy commented 5 years ago

@pragmaware this happens because a POST with a registration_id is considered a request for the creation of a new registration with that id. If that registration_id is already there you can't create a new one with the same registration_id. What is the goal of this request? Creating or updating the registration?

pragmaware commented 5 years ago

This is what the android application does. The function is called "updateDevice" and in theory it's called when the saved token changes. However in my case the saved token ended up to be null. Either because the app crashed in a test or the stored data was deleted. So you cannot trust the app to have the correct token saved. The server crashing on the request, also, makes the app think that the token is NOT registered on the other side and not storing the token in the preferences. Kind of a vicious circle.

The server should not trigger an error when a registration token already exists: it should simply say "OK" and do nothing. I think that this would solve "desync" problems in most cases. Now that I think of it, I'd even make the "updateDevice" call always, not just when the stored token changes. This would catch and fix storage problems on the server side too.

By the way, I don't seem to be able to send notifications to the apps even from the firebase console. Both android and iOS don't seem to work. I guess there is some configuration issue?