Skip to content
Snippets Groups Projects
Select Git revision
  • 76835f89c65302b9e73903353e42e6c65542d3e5
  • master default protected
  • set-sast-config-1
  • v2.2.3
  • v2.2.2
  • v1.4.0
  • v1.3.0
  • v1.2.1
  • v1.2.0
  • v1.1.2
  • v1.1.1
11 results

OAuth2.pm

Blame
  • api.js 708 B
    import baseFetch from "unfetch";
    
    import { AuthStore } from "./stores";
    
    export const fetch = async (
      url,
      { headers = {}, expectedStatus = 200, method = "GET", body = null } = {}
    ) => {
      const { isAuthenticated, user } = AuthStore.getRawState();
    
      if (isAuthenticated) {
        headers.Authorization = "Bearer " + user.accessToken;
      }
    
      if (!headers["Content-Type"]) {
        headers["Content-Type"] = "application/json";
      }
    
      const response = await baseFetch(process.env.REACT_APP_API_BASE_URL + url, {
        body,
        method,
        headers,
      });
    
      if (!!expectedStatus && response.status !== expectedStatus) {
        throw new Error(`Unexpected status code ${response.status}`);
      }
    
      return response;
    };