Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge, chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, minimum-scale=1">
<title>Accountkit</title>
</head>
<body>
<script src="https://sdk.accountkit.com/en_US/sdk.js"></script>
<script>
// awaitPostMessage() This is needed as window.postMessage is not working gracefully for android
function awaitPostMessage() {
var isReactNativePostMessageReady = !!window.originalPostMessage;
var queue = [];
var currentPostMessageFn = function store(message) {
if (queue.length > 100) queue.shift();
queue.push(message);
};
if (!isReactNativePostMessageReady) {
var originalPostMessage = window.postMessage;
Object.defineProperty(window, 'postMessage', {
configurable: true,
enumerable: true,
get: function () {
return currentPostMessageFn;
},
set: function (fn) {
currentPostMessageFn = fn;
isReactNativePostMessageReady = true;
setTimeout(sendQueue, 0);
}
});
window.postMessage.toString = function () {
return String(originalPostMessage);
};
}
function sendQueue() {
while (queue.length > 0) window.postMessage(queue.shift());
}
}
awaitPostMessage();
function loadAccountKit()
{
AccountKit.init(
{
appId: 533770340330052,
state: new Date().getTime(), // This should be your XSRF_TOKEN
version: "v1.1",
display: "modal",
debug: true, // Helps in understanding what went wrong.
fbAppEventsEnabled: true
}
);
AccountKit.login('PHONE', {},
function (response) {
if (response.status === "PARTIALLY_AUTHENTICATED") {
window.postMessage(JSON.stringify({loggedIn:true}))
}
else if (response.status === "NOT_AUTHENTICATED") {
// handle authentication failure
}
else if (response.status === "BAD_PARAMS") {
// handle bad parameters
}
}
);
}
setTimeout(loadAccountKit,1000)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.