title: How to target a logged user with FCM?
body: <p>I'm very new with push notifications and FCM (Firebase Cloud Messaging) in particular.</p>
  
  <p>I have an app where the user can log in and I want to send push notification to this specific user. The user can be logged in on multiple devices at the same time so the notification must be sent to all this devices.</p>
  
  <p>I know how to send a notification to a specific device as <a href="https://firebase.google.com/docs/cloud-messaging/android/first-message?authuser=0#access_the_registration_token" rel="nofollow noreferrer">I've followed the tutorial from the official documentation</a>, and I have a server where the user is registered.</p>
  
  <p>So I was thinking of saving the token (<code>FirebaseInstanceId.getInstance().getToken()</code>) to my server to then send a push notification to all the tokens saved under this user.</p>
  
  <p>But there are two issues:</p>
  
  <ul>
  <li>What happen if the user logs out and another user logs in as the token is gonna be the same, so it can be a source of errors?</li>
  <li>As the token can expires or not be relevant anymore (the user has changed device or has deleted the app), how can I know which tokens to keep in my database?</li>
  </ul>
  
  <p>That's why I'm thinking that my approach is maybe wrong and there is probably a better way to do that.</p>
  
  <p>I've seen that you can <a href="https://firebase.google.com/docs/auth/admin/manage-users" rel="nofollow noreferrer">manage users directly in Firebase</a>, by authenticate your user using Firebase Authentication. So I'm wondering if this is what I need to do?</p>