[英]How do I check if Parse user is logged in from client-side javascript?
Migrating to my own parse server, how can I rewrite this? 迁移到自己的解析服务器后,如何重写它? I know I can get current user via the request object, but that's on backend javascript code. 我知道我可以通过request对象获取当前用户,但这是在后端javascript代码上。 I am running this javascript to decide whether to redirect to the login page. 我正在运行此javascript,以确定是否重定向到登录页面。 I could do a backend call to check if the user is logged it but that seems too much. 我可以做一个后端调用来检查用户是否被登录了,但这似乎太多了。
var user = Parse.User.current();
if (user == null) {
window.location = '/';
} else {
user.fetch().then(function(user) {
if (!user.get("emailVerified")) {
window.location = "verify_email.html";
}
});
}
I am using this and it works with parse-server 我正在使用它,它可以与解析服务器一起使用
var currentUser = Parse.User.current();
if (currentUser) {
// do stuff with the user
console.log('User is logged in');
} else {
// show the signup or login page
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.