3.0.4 • Published 6 months ago

cubeforall v3.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

How to use platform library in ReactJS

Install cube-platform npm package.

npm install cubeforall

Import cube-platform into ReactJS application.

import { init, auth, client, subscription } from 'cubeforall';

Initialize the platform instance.

init('<your-service-id>', '<your-client-id-on-azure-b2c>', '<environment>', '<login-type>');

// environment value: dev | sandbox | prod
// if environment value is not specified then default is 'prod'

// login-type value: silent | popup | redirect
// if login-type value is not specified then default is popup

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);
  });
};

Call check subscription handler to get subscription data.

const checkSubscription = () => {
  subscription.checkSubscription().then((response) => {
    // your code here
    // console.log(response);
  });
};

Call guard handler for checking SSO session.

const yourFunction = () => {
  auth.guard().then((response) => {
    // your code here
    // console.log(response);
  });
};

Call guardV2 for checking SSO session & handle concurrent access.

- use this once login success to create concurrent token
auth.guardV2('signIn').then((response) => {
  // your code here
  // console.log(response);
});
- use this for checking SSO & concurrent access session
  auth.guardV2().then((response) => {
    // your code here
    // console.log(response);
  });

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>

Send Request

platform.client
  .sendRequestAsync(
    '<target-service-id>',
    '<contract-name>',
    '<contract-version>',
    '<contract-method>',
    new {}() /*request payload*/
  )
  .then((response) => {
    // process response
  })
  .catch((err) => {
    // handle error
  });

How to use platform library with Script Tag

Include script tag into your application.

<script src="https://unpkg.com/cubeforall@<will-be-version-here>/dist/platform.min.js"></script>

Initialize the platform instance.

platform.init('<your-service-id>', '<your-client-id-on-azure-b2c>', '<environment>');

// environment value:
// 'sandbox'
// 'prod'
// if environment value is not specified then default is 'prod'

// silent value:
// true
// false
// if silent value is not specified then default is false

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 check subscription handler to get subscription data.

platform.subscription.checkSubscription().then((response) => {
  // your code here
  // console.log(response);
});

Call platform signOut inside handler of click event for logout button.

logoutButton.addEventListener('click', () => {
  platform.auth.signOut().then((response) => {
    window.location.reload();
  });
});

Send Request

platform.client
  .sendRequestAsync(
    '<target-service-id>',
    '<contract-name>',
    '<contract-version>',
    '<contract-method>',
    new {}() /*request payload*/
  )
  .then((response) => {
    // process response
  })
  .catch((err) => {
    // handle error
  });

Thank You!

3.0.4

6 months ago

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0

8 months ago

2.1.39

9 months ago

2.1.38

12 months ago

2.1.37

12 months ago

2.1.36

1 year ago

2.1.34

1 year ago

2.1.32

1 year ago

2.1.33

1 year ago

2.1.31

1 year ago

2.1.29

1 year ago

2.1.30

1 year ago

2.1.27

1 year ago

2.1.28

1 year ago

2.1.26

1 year ago

2.1.25

1 year ago

2.1.24

1 year ago

2.1.23

1 year ago

2.1.22

1 year ago

2.1.21

1 year ago

2.1.20

1 year ago

2.1.16

1 year ago

2.1.17

1 year ago

2.1.15

1 year ago

2.1.18

1 year ago

2.1.19

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

1.1.41

1 year ago

1.1.40

1 year ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.39

1 year ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.30

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.35

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.12

2 years ago

1.0.44

2 years ago

1.1.11

2 years ago

1.0.43

2 years ago

1.1.10

2 years ago

1.1.16

2 years ago

1.0.48

2 years ago

1.1.15

2 years ago

1.0.47

2 years ago

1.1.14

2 years ago

1.0.46

2 years ago

1.1.13

2 years ago

1.0.45

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.0.54

2 years ago

1.1.21

2 years ago

1.0.53

2 years ago

1.1.20

2 years ago

1.0.52

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.0.40

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.33

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.15

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago