saveFcmToken method

Future<void> saveFcmToken(
  1. String userId
)

Saves the Firebase Cloud Messaging (FCM) token for a user.

Stores the token in Firestore under the user's document for push notifications.

Parameters:

  • userId: The ID of the user to associate the token with.

Implementation

Future<void> saveFcmToken(String userId) async {
  String? token = await FirebaseMessaging.instance.getToken();
  if (token != null) {
    await FirebaseFirestore.instance.collection('users').doc(userId).set({
      'fcmToken': token,
      'updatedAt': FieldValue.serverTimestamp(),
    }, SetOptions(merge: true));
  }
}