How to use the @axa-fr/react-oidc-context-fetch.withAuthentication function in @axa-fr/react-oidc-context-fetch

To help you get started, we’ve selected a few @axa-fr/react-oidc-context-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AxaGuilDEv / react-oidc / examples / context / src / Pages / Home / Home.jsx View on Github external
.then(() => alert('fetch end'))
        .catch(e => alert(e));
    },
  })),
);

const Button403 = ({ handleClick }) => (
  <button type="button">
    Simulate 403
  </button>
);

const Button403Enhance = enhance403(Button403);

const enhanceFetch = compose(
  withAuthentication(fetch),
  withProps(props =&gt; ({
    handleClick: e =&gt; {
      e.preventDefault();
      props
        .fetch('http://localhost:3000/')
        .then(() =&gt; alert('fetch end'))
        .catch(e =&gt; alert(e));
    },
  })),
);
const ButtonFetch = ({ handleClick }) =&gt; (
  <button type="button">
    Simulate Fetch
  </button>
);
github AxaGuilDEv / dojo-react-oidc-context / exercice-sample / src / Pages / Projects / Projects.container.js View on Github external
}
});

const withFetch = withHandlers({
  getProjects: props => async () => {
    const response = await props.fetch(getProjectsUrl);
    if (response.status !== 200) {
      throw response.statusText;
    }
    return response.json();
  }
});

export default compose(
  projectsState,
  withAuthentication(fetch),
  withFetch,
  lifecycleHoc
)(Component);
github AxaGuilDEv / react-oidc / examples / context / src / Pages / Home / Home.jsx View on Github external
import { withAuthentication } from '@axa-fr/react-oidc-context-fetch';

const fetchMock = status =&gt; (url, options) =&gt; {
  return new Promise(resolve =&gt; {
    setTimeout(
      () =&gt;
        resolve({
          status,
        }),
      350,
    );
  });
};

const enhance401 = compose(
  withAuthentication(fetchMock(401)),
  withProps(props =&gt; ({
    handleClick: e =&gt; {
      e.preventDefault();
      props
        .fetch('http://www.demo.url')
        .then(() =&gt; alert('fetch end'))
        .catch(e =&gt; alert(e));
    },
  })),
);

const Button401 = ({ handleClick }) =&gt; (
  <button type="button">
    Simulate 401
  </button>
);

@axa-fr/react-oidc-context-fetch

Inject authentification behavior to fetch using react High Order Component

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis