2.1.23 • Published 10 days ago

cubeforall v2.1.23

Weekly downloads
-
License
ISC
Repository
-
Last release
10 days 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>', '<silent>');

// 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:

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

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!

2.1.23

10 days ago

2.1.22

16 days ago

2.1.21

18 days ago

2.1.20

18 days ago

2.1.16

1 month ago

2.1.17

1 month ago

2.1.15

1 month ago

2.1.18

1 month ago

2.1.19

1 month ago

2.1.2

1 month ago

2.1.1

2 months ago

1.1.41

2 months ago

1.1.40

2 months ago

1.1.38

2 months ago

1.1.37

2 months ago

1.1.36

2 months ago

1.1.39

2 months ago

1.1.29

9 months ago

1.1.28

9 months ago

1.1.30

9 months ago

1.1.34

9 months ago

1.1.33

9 months ago

1.1.32

9 months ago

1.1.31

9 months ago

1.1.35

8 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.1.9

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.12

9 months ago

1.0.44

9 months ago

1.1.11

9 months ago

1.0.43

10 months ago

1.1.10

9 months ago

1.1.16

9 months ago

1.0.48

9 months ago

1.1.15

9 months ago

1.0.47

9 months ago

1.1.14

9 months ago

1.0.46

9 months ago

1.1.13

9 months ago

1.0.45

9 months ago

1.1.19

9 months ago

1.1.18

9 months ago

1.1.17

9 months ago

1.0.49

9 months ago

1.0.51

9 months ago

1.0.50

9 months ago

1.1.23

9 months ago

1.1.22

9 months ago

1.0.54

9 months ago

1.1.21

9 months ago

1.0.53

9 months ago

1.1.20

9 months ago

1.0.52

9 months ago

1.1.27

9 months ago

1.1.26

9 months ago

1.1.25

9 months ago

1.1.24

9 months ago

1.0.40

11 months ago

1.0.42

10 months ago

1.0.41

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.33

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.15

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago