1.0.0 • Published 2 years ago
cube-platform-ppd v1.0.0
How to use platform library in ReactJS
Install cube-platform-ppd npm package.
npm install cube-platform-ppd
Import cube-platform-ppd into ReactJS application.
import { init, auth, client } from 'cube-platform-ppd';
Initialize the platform instance.
init('<your-service-id>', '<your-client-id-on-azure-b2c>');
Register your handler after autheticating successfully as below:
auth.handleLoginRedirect((authenticatedAccount) => {
// your code here
// console.log(authenticatedAccount);
// console.log(platform.auth.getActiveAccount());
});
login handler of click event for login button.
const login = () => {
auth.signIn().catch((error) => {
console.error(error);
});
}
logout handler of click event for logout button.
const logout = () => {
auth.signOut().then((response) => {
// your code here
// setIsSignedIn(false);
// window.location.reload();
});
}
Create login button in your html page.
<button id="loginButton" onClick={login}>Login with CCN</button>
Create logout button in your html page.
<button id="logoutButton" onClick={logout}>Logout</button>
How to use platform library with Script Tag
Include script tag into your application.
<script src="platform.min.js"></script>
Initialize the platform instance.
platform.init('<your-service-id>', '<your-client-id-on-azure-b2c>');
Register your handler after autheticating successfully as below:
platform.auth.handleLoginRedirect((authenticatedAccount) => {
// your code here
// console.log(authenticatedAccount);
// console.log(platform.auth.getActiveAccount());
});
Create login button in your html page.
<button id="loginButton">Login with CCN</button>
Create logout button in your html page.
<button id="logoutButton">Logout</button>
Call platform signIn inside handler of click event for login button.
loginButton.addEventListener('click', () => {
platform.auth.signIn().catch((error) => {
console.error(error);
})
});
Call platform signIn inside handler of click event for login button.
logoutButton.addEventListener('click', () => {
platform.auth.signOut().then((response) => {
window.location.reload();
});
});
Thank You!
1.0.0
2 years ago