Firebase phone authentication issue - android

I have setup firebase phone authentication for my react-native android app published on play store. The registration process of the user occurs as follows:
User fills registration information -> OTP is received via Firebase -> User clicks on Verify -> OTP is verified on firebase and the mobile number is added as an identifier in firebase -> user is registered on our server.
Basically the app flow is working well with no issues. When we wanted to reset the database, all the registered users were deleted from our servers and from the firebase authentication table. Now the weird part is, when a user that was already registered (before the database reset) tries to register again (same mobile number) on our app, without the need of inputting any OTP, he is directly added to the firebase user table (without the need of inputting any OTP). If the user is new (never registered before), the flow works normally.
To my understanding, if the mobile numbers are not deleted from firebase table, the user will not receive an OTP when he tries to register again (already registered) however this is only because the user number is already present in the firebase user table, and once the user is deleted, he should be able to register as a new user again.
Please advise how to fix this issue.

Related

Is there a way to receive broadcast when uninstall dialog box appears in android?

In my app, when a user logs in, device token is stored in server database. So when user tries to log in with same account in another device, if token is already present then user is unable to log in. So I want to delete token when user account is not in that device anymore. So when user logs out, device token is deleted in server.
Problem occurs when user uninstalls app and installs again. Then user is unable to login with same account because token is not deleted in server. Is there a way to receive broadcast when dialog box 'do you want to uninstall' appears, so that token can be deleted in server?
I don't think it's possible with FCM alone. However, you can achieve this using multiple Firebase features. Just track the uninstalls using app_remove event of Google Analytics. Then, you can trigger a Cloud Function using that event in order to delete the token in your server. You can read more about it here.

Firebase: Add device token ID to all old users

I have published an android app that uses Firestore for the database. Now, I want to enable push notifications.
I have figured out I need to attache a device token id for each user to send notification to a specific device. The problem is that I have lots of old users! Is there anyway to add token id for each one instead of waiting for all users to upgrade the app?
The only way you can collect device tokens is from the device itself. So, your users will have to upgrade their app to version that collects the tokens, associates it with the user, and writes it to Firestore.

How to handle Firebase Registration IDs(tokens) when multiple users use the same device to access the same app [duplicate]

This question already has an answer here:
When to register an FCM token for a user
(1 answer)
Closed 4 years ago.
Is a firebase token ID based on the device's characteristics, such as IMEI for phones, MAC for PC, etc.. ?
My primary concern is the following:
Multiple users use a given device to access the same app ( Think FB ).
User 1 logs to the app and Firebase provides a token ( E.g. FirebaseInstanceId.getInstance().getInstanceId() ).
User 1 does a logout
User 2 logs in.
Is the same Firebase registration token from #1 going to be used now for User 2?
Is a new firebase ID generated for User 2 or is this something that needs to be handled manually by the app itself?
I have the feeling that this is more a responsibility of the app developer where they monitor who logs in and so forth and the old registration ID is cancelled while a new one is generated for this new login ?
Just to clarify - I only use Firebase Cloud Messaging and nothing else from Firebase so I will be managing the notifications from my own server. This means that I will be storing the Firebase registration IDs in my own database to know for which Firebase Registration ID to generate a notification (e.g. user receives a message from another user), for example.
According to the Firebase Docs:
The registration token may change when:
The app deletes Instance ID
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.
This means the token won't change when user 1 logs out. A work-around would be calling deleteInstanceId() on user log out. This will delete the current Instance ID and a new Instance ID will be generated asynchronously if Firebase Cloud Messaging auto-init is enabled.
Please note that the docs also mention this is a blocking function so do not call it on the main thread.

FCM Documentation not really telling what happens after uninstall's fcm id which already stored in that app server

https://firebase.google.com/docs/cloud-messaging/android/client
Assume my app storing user's fcm token into my own server on user profile.
if the user has multiple device,then he will have multiple fcm id on his profile.
one of the mobile user uninstalls the app, then how to remove that fcm registered token id from user's profile which already stored.
A simple solution is that when you are storing token of a user in your database then at the same time save the device's UUID as well which will identify that device. Now, if a user deletes the application and re-installs later then a new token will be sent to server from the same UUID. Detect that and update the old token.
Case 2 is that if user doesn't reinstall the app then would the token will remain save in DB?, to detect the application deletion a Receiver is implemented which detects event if user is upto delete the application (How can an app detect that it's going to be uninstalled?) . Inform your server about that event and disable that id.
Why I'm not asking for deletion?
The Receiver detects when user opens app deletion dialog. But what if user goes back and doesn't delete the app? in that case whenever user open's the application inform the server that app was not deleted. This thing could be handled by saving a boolean value in sharedPreferences.

Is FCM (firebase cloud messaging) Token for one device or for one account?

I want to store FCM token in my android app user's table in database when user register to the app . When i want to send notification to specific user then i will fetch Token from corresponding row and send push notification.But i am confused that whenever app user logout from his app and register new account from same device ,then there will be two row and hence two Token for same device on database. How to handle such case? What happen to old Token in device? please anyone can help me??
The Instance ID token used to send FCM messages represents the instance of and app on a device. The current user of the app would not affect the token that represents the app instance. Uninstalling and reinstalling the app would cause a new token to be generated but not for in app behaviour like switching users.
You should still remove the mapping of the token to the user on logout and add a new mapping with the same token to the user that logs in but it will be the same token.
I probably feel this may help you,
When user logs out clear his device token and make him Logout so that he won't be able to receive the updates and hence only one user at a time can get the updates

Categories

Resources