This reference describes the Aladin Javascript Software Developer Kit (SDK) reference. For complete Aladin documentation, see docs.aladin.org. There is also reference material available for both the iOS SDK and Android SDK.
$ npm install aladinInstall aladin.js with npm.
npm install aladin --save
Import Aladin into your project.
import * as aladin from 'aladin'
Wire up a sign in button.
document.getElementById('signin-button').addEventListener('click', function() {
aladin.redirectToSignIn()
})
Wire up a sign out button.
document.getElementById('signout-button').addEventListener('click', function() {
aladin.signUserOut(window.location.origin)
})
Include the logic to load user data and to handle the authentication response.
function showProfile(profile) {
var person = new aladin.Person(profile)
document.getElementById('heading-name').innerHTML = person.name()
document.getElementById('avatar-image').setAttribute('src', person.avatarUrl())
document.getElementById('section-1').style.display = 'none'
document.getElementById('section-2').style.display = 'block'
}
if (aladin.isUserSignedIn()) {
const userData = aladin.loadUserData()
showProfile(userData.profile)
} else if (aladin.isSignInPending()) {
aladin.handlePendingSignIn()
.then(userData => {
showProfile(userData.profile)
})
}
Create a manifest.json file
{
"name": "Hello, Aladin",
"start_url": "localhost:5000",
"description": "A simple demo of Aladin Auth",
"icons": [{
"src": "https://helloaladin.com/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
}]
}
Make sure your manifest.json file has appropriate CORS headers so that it
can be fetched via an http GET from any origin.
Serve your application
You can import aladin.js as a script without using a package manager. To securely use the latest distribution of aladin.js from a CDN, add the following script declaration in your application.
<script src="https://unpkg.com/blockstack@1.0.1/dist/blockstack.js" integrity="sha384-7icikTI7lxmv5Qn38XoUm9Quc2uZ0XNgS2BQYg8yUvQ3oikUc19j4dmxA0OW260l" crossorigin="anonymous"></script>
Generated using TypeDoc