@kenetto/kenetto-authenticator
v0.0.9
Published
Kenetto Authenticator
Downloads
8
Readme
Kenetto-Authenticator
Usage
Install kenetto-authenticator via npm.
npm install --save @kenetto/kenetto-authenticator
Import the necessary components
import Auth, { Authenticator } from '@kenetto/kenetto-authenticator'
Create the configurationAuth0
with the necessary credentials. This should come from the environment variables.
The configuration must include domain, clientID, responseType, audience, scope and returnURI
Create an instance of the Auth
class, which you will use for authentication.
const auth = new Auth(configurationAuth0, '/')
and add the following code to your render
function inside of the <Switch />
Component:
<Route
exact
path={auth.callbackUrl}
render={props => {
return (
<Authenticator auth={auth} {...props}>
<div>loading...</div>
</Authenticator>
)
}}
/>
The <div>loading...</div>
should be replaced with the loading component of the app.
This component will be shown when login occurs and will stay visible until the resolution of the authentication.
Use the auth.isAuthenticated()
to check if user is authenticated. The function returns a boolean
with the result.
Use the auth.logout(function)
method to logout. The method should receive a function which will push the next page path.
auth.logout(history.push)
Use the auth.login(redirectURI)
to login and redirect to pretended web page which needs to be passes to the method as a property.
auth.login('/patients')
Use auth.getProfile()
to get the profile of the currently logged user. The method receives a callback function and returns (err, profile)
.
auth.getProfile((error, profile) => {
if (error) {
...
}
if (profile) {
---
}
})