Home > database >  How to update a cloud firestore document at a particular time in the future in my flutter app
How to update a cloud firestore document at a particular time in the future in my flutter app

Time:11-28

I am new to programming, and flutter is my first attempt at making mobile apps. I app working on an app and i would like it to have a function where i can update user documents on firestore at a particular time in the future. For instance, change their account status from "ACTIVE" to "INACTIVE" in exactly "One year" from the time they registered their accounts. I have a sample code which i will paste below to show an example of what i already have. Any ideas as to how to achieve this would be highly appreciated. Thank You.

 await _firestore
                .collection('users')
                .doc(_firebaseAuth.currentUser.uid)
                .set({
              'email': _email,
              'timeOfCreation': FieldValue.serverTimestamp(),
              'accountStatus': 'ACTIVE'
            });

CodePudding user response:

This is not something you want to do on the client side. You would want to write a Google Cloud Function that checks the creation date and sets the status to inactive if it's been a year, or whatever specified time frame. Otherwise, it could only update if they keep the app installed and device connected to the internet.

  • Related