1

I have a server, and multiple clients (web & mobile). When my users log in, I want to start sending them notifications about the content they follow. When they log out, I want to stop sending them notifications.

I've found many Stack Overflow questions that are similar to mine, but none have been completely answered.

The closes to my question was this other question where the accepted answer is to call deleteInstanceId() when the user logs out, which seems like the most solid solution, but in the comments someone copy pasted from the (GCM) docs that "Developers should never unregister the client app as a mechanism for logout or for switching between users". I wasn't able to find the same notice in the new Firebase docs, but I assume that it's the same concept: the InstanceId is not supposed to be user related.

The only alternative I've found, is to send a "signOut" request to my server, with the instanceId, and my server needs to remove the associated instanceId from the user account. But what if that API call doesn't go through? This seems to be quite a fragile solution.

So this is what I would do now:

  1. Send the instanceId to my server when the user authenticates
    • Make sure that this same instanceId is not used by another user, since this could happen when the other user logged out on the same device, but the API call didn't go through
  2. When sending notifications, send them directly to the registered instanceIds (initially I had planned on using topics, but in combination with handling my tokens, this seems even more fragile).
  3. When the user logs out, send a signOut request to my API, and remove the instanceId from the user.
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
enyo
  • 16,269
  • 9
  • 56
  • 73
  • If your scheme is working for you, then your job is done, right? Or there a specific problem here that still exists? – Doug Stevenson Jun 07 '19 at 13:23
  • @DougStevenson I haven't implemented this yet, and it seems like a solution that's a bit fragile to me (and a lot more difficult than simply invalidating an instance locally). I just wanted input from people that already have implemented this, to be sure that this is the correct approach. – enyo Jun 07 '19 at 13:28

1 Answers1

1

Your question seems to just be seeking validation for a design, which really isn't the purpose of Stack Overflow. The Firebase subreddit might be a better alternative for drumming up conversation around the problem.

But I will say that if it works for you, then run with it. Consider also sending the target users's UID in each message, and have your app compare that with the currently signed in user in order to determine if it reached its correct destination. Send a message back to the server if it's not in order to correct the problem.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441