So, on my app, I noticed a logged-in time for a user that was two days in the future. Trying to figure out how that was possible as I have the last_login set to be updated by the GLOBAL > Current Time.
Can that time be manipulated if the user changes the date and time on their device?
YES!
To test this, I changed the date and time on my phone to a future date, and sure enough, GLOBAL > Current Time
rendered the device's set date and time in the future.
This affects many things such as chat messages being shown out of order since one user may always have timestamps in the future or past.
Before I go trying to create a cloud function that renders the true time, Is there a known solution that I'm missing? Seems like this would be a bigger deal and that I'm missing some easy FF solution.
Partial solution:
I've found that you can use Firestore Server Timestamp when selecting a timestamp data type field when updating a record in an action. HOWEVER, I have not been able to obtain that same server timestamp in a custom function.I have a custom function that adds 7 days to a date (for a subscription service expiration). My custom function takes the current time and adds 7 days. The current solution is to have an action write to the user's collection (I'm using login_time) with the Firestore Server Timestamp and then reference that field as an argument in the custom function. Here is the custom function that adds login_time as the defined argument (firebaseTime) and returns the 7 days from the server time.
DateTime add7DayDate() {
final DateTime FirebaseTime = firebaseTime!;
final DateTime sevenDays = FirebaseTime.add(Duration(days: 7));
return sevenDays;
}
return add7DayDate();