parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.7k stars 4.76k forks source link

Remove unregistered FCM tokens #9085

Closed mtrezza closed 4 days ago

mtrezza commented 2 months ago

New Feature / Enhancement Checklist

Current Limitation

Google notified in April 2024 that:

Starting May 15, 2024, the stale tokens and topic subscriptions for devices, which have not been connected to FCM in over 270 days, will be considered as expired and invalid. If a request is sent to an invalid token, it will be rejected with a 404 (UNREGISTERED) error.

We recommend you to confirm that your service handles 404 error codes from FCM correctly. Please delete your record of any tokens with a 404 response code because they will not be valid again.

It doesn't seem that Parse Server would be properly handling this UNREGISTERED error, but it's hard to tell how these errors provided by the push adapter translate to the existing error strings:

https://github.com/parse-community/parse-server/blob/242002432fa305aa1c68b07679582164f560bda8/src/StatusHandler.js#L240-L243

Feature / Enhancement Description

Ensure that Parse Server deletes "unregistered" tokens.

3rd Party References

parse-github-assistant[bot] commented 2 months ago

Thanks for opening this issue!

jimnor0xF commented 1 month ago

Would very much like this feature merged in, so I think I'll look into this soon.

FCM returns the following error object when not registered: {"code":"messaging/registration-token-not-registered","message":"Requested entity was not found."}

So could perhaps simply add an additional check on the code key there.

mtrezza commented 1 month ago

Yes, the errors are passed in an array from the push adapter to Parse Server, which then removes the tokens based on the error message. You could just add the error text to that logic I've mentioned above.

Side note: the current solution is not elegant, because the logic in which the errors are parsed is in Parse Server, but it seems that it should be in the push adapter, since these errors are push API specific. Opened https://github.com/parse-community/parse-server-push-adapter/issues/244.

mtrezza commented 4 days ago

I think we urgently need this fix, as developers will need to adopt the push adapter 6.2.0 due to the API sunset. In addition, Parse Server 7.1.0 comes with push adapter 6.2.0 integrated.

In short, the FCM API v1 error codes do not apply to FCM API v2.

parseplatformorg commented 4 days ago

🎉 This change has been released in version 7.1.0-alpha.13