/* eslint-disable no-console */ import { createAuth0Client } from '@auth0/auth0-spa-js'; createAuth0Client({ domain: 'dev-er0xnh1z6mcpragr.us.auth0.com', clientId: 'zUS5SRUod01HNbw9aW02ZharfsFiOh2G', useRefreshTokens: true, //required for Safari x-site cookie issue cacheLocation: 'localstorage', //required for Safari x-site cookie issue authorizationParams: { redirect_uri: window.location.origin, }, }).then(async (auth0Client) => { // Assumes menu item with id "login" in the DOM const loginMenu = document.getElementById('loginMenu'); if (loginMenu) { loginMenu.addEventListener('click', (e) => { e.preventDefault(); auth0Client.loginWithRedirect(); }); } // login button const loginButton = document.getElementById('loginButton'); if (loginButton) { loginButton.addEventListener('click', (e) => { e.preventDefault(); auth0Client.loginWithRedirect(); }); } // Remove the login tokens form the URL if ( location.search.includes('state=') && (location.search.includes('code=') || location.search.includes('error=')) ) { console.log('Here 1'); /////////////////////////////////////////////////// Here 01 await auth0Client.handleRedirectCallback(); window.location.replace('/restricted/wi-resources'); //window.history.replaceState({}, document.title, '/restricted/wi-resources'); } // Assumes a button with id "logout" in the DOM const logoutButton = document.getElementById('logout'); if (logoutButton) { logoutButton.addEventListener('click', (e) => { e.preventDefault(); auth0Client.logout(); console.log('Logout Pressed'); }); } const isAuthenticated = await auth0Client.isAuthenticated(); const userProfile = await auth0Client.getUser(); if (isAuthenticated) { // we're logged in // set menu visibility //document.getElementById('loginMenu').style.display = 'none'; if (loginMenu) { loginMenu.style.display = 'none'; } //document.getElementById('logout').style.display = 'inline-block'; if (logoutButton) { logoutButton.style.display = 'inline-block'; } console.log('Is logged IN'); } else { // we're NOT logged in, so restrict access // set menu visibility //document.getElementById('loginMenu').style.display = 'inline-block'; //document.getElementById('logout').style.display = 'none'; if (loginMenu) { loginMenu.style.display = 'inline-block'; } //document.getElementById('logout').style.display = 'inline-block'; if (logoutButton) { logoutButton.style.display = 'none'; } const accessCard = await document.getElementById('restricted'); if (accessCard) { accessCard.href = '/login'; } // bounce to login page for any page in the 'restricted' folder console.log('Is logged OUT'); if (window.location.href.includes('restricted')) { window.location.replace(window.location.origin + '/login'); } } });