import appConfig from '../config/appConfig.json';

//should only be used during signup and login flow to authenticate user
export function fetchAuth(endpoint, body, userAuthToken) {
  const request = {
    method: endpoint.method,
    headers: {
      Authorization: (!userAuthToken ? appConfig.appSecret : userAuthToken),
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  };

  return fetch(endpoint.url, request).then(res => res.json());
}

//should be called after user has been authenticated inorder to access rest of applications api services on the baclend
export function fetchGeneric(endpoint, body) {
  return fetchAuth(endpoint, body, 'realm-user-auth-token');
}
