@moxoff/axiom-auth
v0.2.2
Published
Keycloak component for react application
Downloads
35
Keywords
Readme
Axiom Auth
Axiom Auth is a React Keycloak based component that helps Moxoff application to be protected with Keycloak authentication.
Install
Add Axiom Auth to your project.
npm install --save @moxoff/axiom-auth
Use
Import the provider to wrap your application
import { KeycloakProvider } from '@moxoff/axiom-auth';
and use them like so
function AppWithAuth() {
const app = (
<ThemeProvider theme={theme}>
<Router>
<Routes />
</Router>
</ThemeProvider>
);
return <KeycloakProvider env={env}>{app}</KeycloakProvider>;
To use the keycloak functions you can import the following hooks
import { useKeycloak } from '@moxoff/axiom-auth';
and use them like so
...
const YourComponent = () => {
const [userName, setUserName] = useState(null);
const { keycloak, authenticated } = useKeycloak();
useEffect(() => {
const loadUser = async () => {
await keycloak()
.loadUserInfo()
.then(info => {
setUserInfo(info.name);
});
};
if (userInfo === null && authenticated() === true) {
loadUser();
}
}, [authenticated, keycloak, userInfo]);
return <>{User Name: ${userInfo}}</>
}
Dependencies
This componente is based on "keycloak-js": "^9.0.0"
Before to use this componente be sure to install the following dependencies in your project:
"prop-types": ">=15.7.0",
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
Contribute
To release a new version simply run:
npm version patch
or npm version minor
or npm version major
.
This will automatically increase the version number, commit and push a tag that will trigger the release'