// Check if the user is logged in const getCookie = (returnType) => { let decodedCookie = decodeURIComponent(document.cookie); if (decodedCookie == "") { return; } let ca = decodedCookie.split(','); const token = ca[0].split("token=")[1]; const type = ca[1].split("type=")[1]; const expiresDay = ca[2].split("expires=")[1]; const expiresDate = ca[3] const expires = `${expiresDay}${expiresDate}` if (returnType == "token") { return token; } else if (returnType == "type") { return type } else if (returnType == "expires") { return expires; } return null; } const token = getCookie("token"); if (token == undefined) { // no user window.location.href = '/'; } console.log('user token');