improve structure

This commit is contained in:
Maurits van der Schee 2018-10-09 14:09:19 +02:00
commit b6bb6950e3

View file

@ -8,8 +8,12 @@ var audience = ''; // api audience as defined in auth0
window.onload = function () {
var match = RegExp('[#&]access_token=([^&]*)').exec(window.location.hash);
var accessToken = match && decodeURIComponent(match[1].replace(/\+/g, ' '));
document.location.hash = '';
if (accessToken) {
if (!accessToken) {
redirectUri = document.location.href;
url = 'https://'+domain+'/authorize?audience='+audience+'&response_type=token&client_id='+clientId+'&redirect_uri='+redirectUri;
document.location = url;
} else {
document.location.hash = '';
url = '/api.php/records/posts?join=categories&join=tags&join=comments&filter=id,eq,1';
var req = new XMLHttpRequest();
req.onreadystatechange = function () {
@ -22,10 +26,6 @@ window.onload = function () {
req.open("GET", url, true);
req.setRequestHeader('X-Authorization', 'Bearer '+accessToken);
req.send();
} else {
redirectUri = document.location.href;
url = 'https://'+domain+'/authorize?audience='+audience+'&response_type=token&client_id='+clientId+'&redirect_uri='+redirectUri;
document.location = url;
}
};
</script>