watchUserProfile = (dispatch, firebase) => {
  const {
    authUid,
    config: { userProfile, useFirestoreForProfile, enableClaims }
  } = firebase._
  unWatchUserProfile(firebase)

  if (userProfile) {
    if (useFirestoreForProfile && firebase.firestore) {
      firebase._.profileWatch = firebase // eslint-disable-line no-param-reassign
        .firestore()
        .collection(userProfile)
        .doc(authUid)
        .onSnapshot((userProfileSnap) => {
          return enableClaims
            ? firebase
                .auth()
                .currentUser.getIdTokenResult(true)
                .then((token) =>
                  handleProfileWatchResponse(
                    dispatch,
                    firebase,
                    userProfileSnap,
                    token
                  )
                )
            : handleProfileWatchResponse(
                dispatch,
                firebase,
                userProfileSnap,
                null
              )
        }, createProfileWatchErrorHandler(dispatch, firebase))
    } else if (firebase.database) {
      firebase._.profileWatch = firebase // eslint-disable-line no-param-reassign
        .database()
        .ref()
        .child(`${userProfile}/${authUid}`)
        .on(
          'value',
          (userProfileSnap) => {
            enableClaims
              ? firebase
                  .auth()
                  .currentUser.getIdTokenResult(true)
                  .then((token) =>
                    handleProfileWatchResponse(
                      dispatch,
                      firebase,
                      userProfileSnap,
                      token
                    )
                  )
              : handleProfileWatchResponse(
                  dispatch,
                  firebase,
                  userProfileSnap,
                  null
                )
          },
          createProfileWatchErrorHandler(dispatch, firebase)
        )
    } else {
      throw new Error(
        'Real Time Database or Firestore must be included to enable user profile'
      )
    }
  } else if (enableClaims) {
    firebase._.profileWatch = firebase
      .auth()
      .currentUser.getIdTokenResult(true)
      .then((token) => {
        dispatch({
          type: actionTypes.SET_PROFILE,
          profile: { token }
        })
      })
  }
}
Watch user profile. Internally dispatches sets firebase._.profileWatch
and calls SET_PROFILE actions. Supports both Realtime Database and Firestore
@param {Function} dispatch - Action dispatch function
@param {object} firebase - Internal firebase object
@private