sbx-react-auth-hoc
v1.1.4
Published
Authentication wrapper library for sbx
Downloads
148
Readme
sbx-react-auth-hoc
Authentication wrapper library for sbx
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