JS Quick Start
Working Example
Below is a minimal example of the Y8 SDK. Note, the redirect URI on the application settings page needs to match where the app will be hosted. This example requires Y8 storage or a web server to test. Local HTML files have different permissions.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<a href="#" onclick="ID.login(authCallback);">Login</a>
<a href="#" onclick="ID.register(authCallback);">Register</a>
<script>
var authCallback = function(response) {
if (response) {
console.log(response, response.authResponse.details);
}
}
window.idAsyncInit = function() { // SDK downloaded
ID.init({
appId : 'YOUR APP ID'
});
ID.Event.subscribe('id.init', function() { // SDK initialized
ID.getLoginStatus(function(data) { // Try Autologin
if (data.status == 'not_linked' || data.status == 'uncomplete') {
ID.login(loginCallback); // Connect/Request permission
} else {
// Not logged in
}
});
});
};
</script>
<script src="https://cdn.y8.com/api/sdk.js" async></script>
</body>
</html>