0

I am trying to only allow the user to make 1 account on the device so when he makes an account and signs out, and then trys to make a new account it will not make the account and say this device already has an account.I got the device id so far but I dont know what to do now.

Sameer
  • 11
  • 1
  • 6
  • The solution for this will be to get unique ID of device and patch that up with user details. So when anyone or that particular user tries to create account from that particular device you will check in backend if that unique ID exists or not by using `device_info_plus` package check here https://stackoverflow.com/questions/45031499/how-to-get-unique-device-id-in-flutter – Chirag Bargoojar Jun 05 '21 at 01:53
  • how do i check if it exists – Sameer Jun 05 '21 at 01:57

2 Answers2

2

create a table in your database where the combined columns: userid (from new account) and deviceid are unique. use device_info package to get unique device id

method get device id

Future<String> getDeviceId() async {
  var deviceInfo = DeviceInfoPlugin();
  if (Platform.isIOS) {
    var iosInfo= await deviceInfo.iosInfo;
    return iosInfo.identifierForVendor; // on iOS
  } else {
    var androidInfo = await deviceInfo.androidInfo;
    return androidInfo.androidId; // on Android
  }
}
rparejo
  • 331
  • 2
  • 4
1

What I would do is use the unique device id and in firestore create a document in the user collection whose document id is the device id, then to verify that the id already exists it would be to use the following code

FirebaseFirestore.instance
    .collection('users')
    .doc(idDevice)
    .get()
    .then((DocumentSnapshot documentSnapshot) {
      if (documentSnapshot.exists) {
        print('Document data: ${documentSnapshot.data()}');
      } else {
        print('Document does not exist on the database');
      }
    });