diff --git a/terraform/organization/html/index.html b/terraform/organization/html/index.html
index 4bb4f8f..f104189 100644
--- a/terraform/organization/html/index.html
+++ b/terraform/organization/html/index.html
@@ -1,5 +1,6 @@
+
@@ -11,6 +12,7 @@
+
BSMSapp
@@ -18,25 +20,38 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -51,44 +66,50 @@
};
var token = localStorage.getItem('token') || undefined;
- console.log(token)
if (typeof token === 'undefined' || token === null) {
- console.log('no hay token guardado')
- aux = get_token()
- var promiseB = aux.then(function(result) {
+ tokenPromise = get_token()
+ var aux = tokenPromise.then(function (result) {
if (result) {
token = result["access_token"]
localStorage.setItem('token', token);
- console.log(token)
- username = get_user(token)
+ userPromise = get_user(token)
- var prom = username.then(function(result) {
+ var prom = userPromise.then(function (result) {
username = result["username"]
- localStorage.setItem('username', token);
- console.log(username)
+ $("#loading").hide();
+ $("#myForm").show();
+ $("#tableBtn").show();
+ localStorage.setItem('username', username);
});
}
});
} else {
$("#login").hide();
- $("#loading").show();
- username = get_user(token)
+ username = localStorage.getItem('username') || undefined;
- var prom = username.then(function(result) {
+ if (typeof username === 'undefined' || username === null) {
+ $("#loading").show();
+ } else {
+ $("#myForm").show();
+ $("#tableBtn").show();
+ }
+
+ userPromise = get_user(token)
+ var aux = userPromise.then(function (result) {
$("#loading").hide();
- if (result.hasOwnProperty('error')){
+ if (result.hasOwnProperty('error')) {
+ $("#myForm").hide();
+ $("#tableBtn").hide();
$("#login").show();
localStorage.removeItem('token')
+ alert("Token expired. Log in again!")
} else {
+ username = result["username"]
$("#myForm").show();
$("#tableBtn").show();
- $("#login").hide();
-
- username = result["username"]
- localStorage.setItem('username', token);
- console.log(username)
+ localStorage.setItem('username', username);
}
});
}
@@ -178,15 +199,17 @@
return undefined
}
- $("#myForm").show();
- $("#tableBtn").show();
+ var url = window.location.href.split("?")[0];
+ window.history.replaceState({}, document.title, url);
+
$("#login").hide();
+ $("#loading").show();
const response = await fetch('https://santilococo.auth.us-east-1.amazoncognito.com/oauth2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
- },
+ },
body: new URLSearchParams({
'grant_type': 'authorization_code',
'code': code,
@@ -203,7 +226,7 @@
const response = await fetch('https://santilococo.auth.us-east-1.amazoncognito.com/oauth2/userInfo', {
method: 'GET',
headers: {
- "Authorization" : str
+ "Authorization": str
}
});
@@ -212,16 +235,6 @@
\ No newline at end of file