我们需要检查访问该站点的用户是否已登录。如果没有,则必须将他们重定向到登录屏幕。我尝试过找到here的JS解决方案,但控制台仍在吐出the user is not logged in
,即使它们是。{/ p>
我已经检查过BigCommerce使用的cookie,它似乎仍然使用LoginEmail
//this will allow you to mention the cookie by index
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
//set variable that will check if login email exists
var loggedIn = getCookie('LoginEmail');
//logic that will output different content based on the loggedIn Status
if(typeof loggedIn === 'undefined'){
console.log("They are not logged in!");
window.location.replace("/login.php");
}
else{
console.log("They are logged in! ");
}
我在Stencil的主页上触发了这个。提前谢谢!
答案 0 :(得分:1)
有一个端点将检查用户是否已登录,并从那里根据需要处理响应。我已经在下面添加了一个代码段:
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if ( this.readyState == 4 ) {
if (this.status == 200) {
callback(JSON.parse(this.responseText))
} else {
callback(null);
}
}
};
xhttp.open('GET', "/customer/current.jwt?app_client_id=' + clientId");
xhttp.send();