How to get Firebase token after user Login?

HarshitaHarshita INMember ✭✭✭✭
edited January 2018 in Xamarin.Forms

Here i am getting firebase id token ,and it works fine-
public async override void OnTokenRefresh()
{
refreshedToken = FirebaseInstanceId.Instance.Token;
SendRegistrationToServer(refreshedToken);
}

but how to generate this token only when user login to the app(after click on login button)?
give me sample code for do this.

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭

    FireBase tokens are typically generated at initial startup of your app, so you can do one thing, have the token generated on initial startup of your app, and save it in preferences or settings or local db for later use, until then I assume you'll not be doing any FireBase work for NOT logged in user.

    Later when the user is logged-in you can retrieve the token and use it against the FireBase APIs as required.

    Hope this helps,

    -- N Baua

  • HarshitaHarshita INMember ✭✭✭✭

    what happend when a new user logged in with same device?

  • MarreMarre USMember ✭✭

    I make use of an Azure Notification Hub, so I can just call FirebaseInstanceId.Instance.Token after the login and send that token to the hub. Have you tried calling it manually? No idea if that would work, but it does seem tricky to only use Firebase.

  • @Harshita you have to write your own logic at server(API) to updated username for current device token with new username of logged in user .
    Then for sending notification you can get fcm_token by username and send him notification

  • ukodukod Member

    I think that this piece of manual about Firebase messaging setup will be useful for your problem solution on GitHub: GoogleApisForiOSComponents/blob/master/Firebase.CloudMessaging/component/GettingStarted.md#prevent-auto-initialization

    Check out Prevent Auto Initialization part

  • HarshitaHarshita INMember ✭✭✭✭
    @ukod
    I already solved this. :) this question s asked one year ago.
  • MisikoMisiko Member

    @Harshita

    Can you tell us how did you solve your problem pls ?

  • HarshitaHarshita INMember ✭✭✭✭

    You need to save this token and after success login work with this token,thats it.

  • AswathyAswathy Member ✭✭✭

    @Harshita what happend when a new user logged in with same device, did you solve this?

Sign In or Register to comment.