147ec800 by Jonille Arreglo

27190_loggedin

1 parent bfa168cd
let aiUser = btutil_getCookie('aiwp_logged_in');
let objBody = { aiwp_logged_in: aiUser };
let params = [];
params['objBody'] = objBody;
params['strUrl'] = 'https://test.api.ai-pro.org/e/v1/authenticate/'; //use envvar for https://test.api.ai-pro.org/ only
btutil_checkAuthentication(params, cbCheckAuthentication, cbErrCheckAuthentication);
function cbCheckAuthentication(res) {
// console.log(res);
if (!res.success) {
window.location.href = "https://ai-pro.org/redirect-account-required/"; //use envvar
} else {
document.getElementById("root").classList.add("active");
}
}
function cbErrCheckAuthentication(res) {
console.log(res);
}
\ No newline at end of file
const appendScript = (scriptToAppend, callback = null) => {
const script = document.createElement("script");
script.src = scriptToAppend;
script.async = false;
document.body.appendChild(script);
if(!callback) return;
if(script.readyState) { // only required for IE <9
script.onreadystatechange = function() {
if ( script.readyState === "loaded" || script.readyState === "complete" ) {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
}
export default appendScript;
\ No newline at end of file
......@@ -11,3 +11,7 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
#root:not(.active) {
display: none;
}
\ No newline at end of file
......
......@@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import appendScript from './handlers/appendScript';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
......@@ -15,3 +16,6 @@ root.render(
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
appendScript("https://btcomponent-1devt.s3.us-east-1.amazonaws.com/common/btutil-authenticate.min.js");
appendScript("http://localhost:3000/assets/js/auth.js");
\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!