onDocumentWrittenWithAuthContext method

void onDocumentWrittenWithAuthContext(
  1. Future<void> handler(
    1. FirestoreAuthEvent<Change<EmulatorDocumentSnapshot>?> event
    ), {
  2. @mustBeConst required String document,
  3. @mustBeConst DocumentOptions? options,
})

Event handler that triggers on any write to a document (create, update, or delete), with authentication context.

Similar to onDocumentWritten, but the handler receives a FirestoreAuthEvent that includes AuthType and an optional auth ID.

Example:

firebase.firestore.onDocumentWrittenWithAuthContext(
  document: 'users/{userId}',
  (event) async {
    print('Auth type: ${event.authType}');
    print('Auth ID: ${event.authId}');
    final before = event.data?.before;
    final after = event.data?.after;
  },
);

Implementation

void onDocumentWrittenWithAuthContext(
  Future<void> Function(
    FirestoreAuthEvent<Change<EmulatorDocumentSnapshot>?> event,
  )
  handler, {
  // ignore: experimental_member_use
  @mustBeConst required String document,
  // ignore: experimental_member_use
  @mustBeConst DocumentOptions? options,
}) {
  _registerChangeHandler(
    methodName: 'onDocumentWrittenWithAuthContext',
    document: document,
    validateEventType: _isFirestoreWrittenEvent,
    withAuthContext: true,
    handler: handler,
  );
}