thaipbs-account-client
v0.2.0
Published
JavaScript library for seamlessly authorization between sites under ThaiPBS (thaipbs.or.th)
Readme
ThaiPBS Account JS
JavaScript library for seamlessly authorization between sites under ThaiPBS (thaipbs.or.th)
Installation
Add this script tag in your web page:
<script src="https://account.thaipbs.or.th/sdk/thaipbs-account-client/v0.1.0/ThaiPBSAccountClient.js"></script>You may also use this as a dependency via npm:
npm install thaipbs-account-clientPlease note that when using via npm, you'll be required to use Babel to build your project.
Usage
To get current user info:
// For script tag, ThaiPBSAccountClient will be available globally.
// For npm, please import this.
//
// import ThaiPBSAccountClient from 'thaipbs-account-client';
var client = new ThaiPBSAccountClient();
var user = client.getUserInfo();
if (user) {
console.log('Current user id: ' + user.id);
console.log('Current user name: ' + user.name);
console.log('Current user image: ' + user.image);
}To login:
function onClickLoginButton() {
client.authorize()
.then(function(data) {
if (data && data.user) {
// Hooray! The user is logged in.
}
});
}To show profile or login screen (based on current status):
function onClickProfileButton() {
client.showProfile();
}