Reputation: 1707
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. I am running this javascript to decide whether to redirect to the login page. 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";
}
});
}
Upvotes: 1
Views: 848
Reputation: 2182
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
}
Upvotes: 2