0.2.1 • Published 7 years ago
kenetto-authenticator v0.2.1
Kenetto-Authenticator
Usage
Install kenetto-authenticator via npm.
npm install --save kenetto-authenticator
Import the necessary components
import Auth from 'kenetto-authenticator'
import Authenticator from 'kenetto-authenticator/Authenticator'
Create the webAuthObject
with the necessary credentials.
const webAuthObject = {
domain: 'kenetto.eu.auth0.com',
clientID: <CLIENT_ID>
responseType: 'token id_token',
audience: 'https://api.kenetto.com',
scope: <SCOPE>
}
Create an instance of the Auth
class, which you will use for authentication.
const auth = new Auth('http://localhost:3000/login', <WEB_AUTH_OBJECT>, <RETURN_URL_KEY>, <HOME_PATH>)
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}>
<Callback />
</Authenticator>
}} />
Use the auth.isAuthenticated()
to check if user is authenticated.
Use the auth.logout()
method to logout. The method should receive a method which will push the next page path.
auth.logout(history.push)
Use the auth.login()
to login and redirect to pretended webpage 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) {
---
}
})