Skip to content

Instantly share code, notes, and snippets.

@Hesamedin
Created January 7, 2022 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hesamedin/6f0ab09fe58b2d019bf9b9974d896342 to your computer and use it in GitHub Desktop.
Save Hesamedin/6f0ab09fe58b2d019bf9b9974d896342 to your computer and use it in GitHub Desktop.
Future<void> storePushNotificationToken(String userId, String token) async {
final batch = _firestore.batch();
final pushTokenRef = _firestore.collection(FirestoreCollection.pushToken.path).doc(userId);
batch.set(
pushTokenRef,
{'userId': userId, 'token': token},
SetOptions(merge: true),
);
final pushTokenTokensRef = pushTokenRef.collection(FirestoreCollection.pushTokenTokens.path).doc();
batch.set(
pushTokenTokensRef,
{'token': token, 'valid': true},
SetOptions(merge: true),
);
batch.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment