statguy
statguy

Reputation: 1707

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. 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

Answers (1)

Mazel Tov
Mazel Tov

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

Related Questions