const datanya = JSON.parse(localStorage.getItem('datanya')); // // check local storage if (datanya == null ) { // redirect to login page localStorage.removeItem('datanya'); window.location.href = "/"; } if (datanya.role != 'siswa' && datanya.role != 'guru') { // redirect to login page localStorage.removeItem('datanya'); window.location.href = "/"; } // console.log(datanya); // console.log(datanya.role); const path = window.location.pathname; const segments = path.split('/'); // ["", "kurir", "data"] const target = segments[1]; // console.log(target); fetch(datanya.role== 'guru' ? '/guru/check' : '/siswa/check', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: localStorage.getItem('datanya') }) .then(res => { // if (res.status >= 400) { // // remove local storage // localStorage.removeItem('datanya'); // // redirect to login page // window.location.href = "/"; // } // console.log(res); return res.json(); }) .then(data => { // console.log(data); // document.getElementById('h5-title').innerHTML = data.username; }) .catch(err => { // // console.log(err); // // remove local storage // localStorage.removeItem('datanya'); // // redirect to login page // window.location.href = "/"; });