Source: app/util/getGroupId.js

import authenticate from './auth/authenticate';
import { userGroupIdsSelector } from '../selectors/userAccountSelectors';

/**
 * Retrieve the groupId
 * @param groupId
 * @param getState
 * @returns {Promise<*>}
 */
const getGroupId = async (groupId, getState) => {
  if (groupId) {
    return groupId;
  }

  await authenticate();
  return userGroupIdsSelector(getState())[0];
};

export default getGroupId;