Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store dates in Firestore using Timestamp type instead of String #86

Open
EArminjon opened this issue Sep 23, 2024 · 1 comment
Open

Comments

@EArminjon
Copy link

EArminjon commented Sep 23, 2024

Observation :
Actually RevenueCat store dates as ISO 8601 "string" inside Firestore. This is an issue.

Feature request:
To let us availability to create some Firestores rule based on dates, dates should be of type "Timestamp". Timestamp object can be easily converted to Date() on any Frontend/Backend. So this is not an issue.

Example of current limitation:
Bellow an exemple explaining why we need that :

service cloud.firestore {
  match /databases/{database}/documents {

    function hasPaidSubs() {
      let query = get(/databases/$(database)/documents/users/$(request.auth.uid)/purchaser-info/$(request.auth.uid));
      let subscription = query.data;
      
      return subscription.entitlements.pro != null && subscription.entitlements.pro.expires_date > request.time;
    }
    
     match /cars/{carID} {
      allow read: if true;
      allow create: if request.auth != null && request.auth.uid == request.resource.data.creator && hasPaidSubs()
      allow update: if request.auth != null && request.auth.uid == resource.data.creator
      allow delete: if request.auth != null && request.auth.uid == resource.data.creator;  
    }
  }   
} 

In this example, "expires_date" is of type "string" and equal "2024-08-26T07:43:35Z", the comparaison generated the following exception because it can't be compare with request.time which is of type Timestamp :

Unsupported operation error. Received: string > timestamp. Expected: string > string, bytes > bytes, int > int, float > float, duration > duration, timestamp > timestamp, constraint > any, any > constraint. for 'create' @ L32, cause=null}

If you agree with this suggestion, it will generate a Breaking Change.

Alternative:

Inside Firebase Firestore, the Monitoring Rule test space allow the comparaison between String and Timestamp. But this is a bug and that didn't work on PROD and on Firebase cli Emulator.

I started a conversation with the Firebase support to check this issue and to know if it's possible to allow String to Timestamp conversion or comparaison inside Firestore Rules. If they allow that, i will close this issue.

Maybe we can also upvote this Firebase suggestion : https://firebase.uservoice.com/forums/948424-general/suggestions/48895802-allow-string-to-timestamp-conversion-in-firestore

@EArminjon EArminjon changed the title Store dates in Firestore with Timestamp type instead of String Store dates in Firestore using Timestamp type instead of String Sep 23, 2024
@EArminjon
Copy link
Author

EArminjon commented Sep 27, 2024

Hello @vicfergar, can you check this ? This is really blocker for our business :/
Would like to know if it will be considered or should we fork it and use our own extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant