sbx-react-auth-hoc
TypeScript icon, indicating that this package has built-in type declarations

1.1.4 • Public • Published

sbx-react-auth-hoc

Authentication wrapper library for sbx

NPM JavaScript Style Guide

Install

npm install --save sbx-react-auth-hoc
yarn add sbx-react-auth-h oc

Usage

import React, {useState} from "react";
import { initialize, Auth } from "sbx-react-auth-hoc";
import { SbxCoreService, SbxSessionService } from "sbx-axios";

const sbxCoreService = new SbxCoreService();
const sbxSessionService = new SbxSessionService(sbxCoreService);
sbxSessionService.initialize(process.env.REACT_APP_DOMAIN, process.env.REACT_APP_APP_KEY);

initialize(sbxCoreService, sbxSessionService, process.env.REACT_APP_VALIDATE_CS);

const App = () => {
  const [logged, setLogged] = useState(false);

  function handleLogin() {
    setLogged(true);
  }

  return (
    <div>
      <Auth
        onError={() => {
          console.log("not ok");
        }}
        onSuccess={res => {
          console.log(res);
          setLogged(true);
        }}
        onErrorComponent={<div>not ok</div>}
        logged={logged}
      >
        <div>ok</div>
      </Auth>

      <button onClick={handleLogin}>login</button>
    </div>
  );
};

export default App;

License

MIT © caberrio

Package Sidebar

Install

npm i sbx-react-auth-hoc

Weekly Downloads

77

Version

1.1.4

License

MIT

Unpacked Size

61.4 kB

Total Files

10

Last publish

Collaborators

  • hansospina
  • cadelosreyes
  • alextab93
  • caberrio