Parse, Check to See if the user is logged in

I want to check if my user is registered, I am currently using

if(currentUser == null) { window.location.replace("login.html"); } 

redirect the user to the login page. But I saw tutorials in which the user exchanged if(currentUser) {...} instead of the entire contents of the code.

I was also interested in Parse authenticated() , but the documentation does not indicate how to use it, except that it returns a boolean value.

I just wanted to know if one of these three is faster / more efficient than the other, and if the parsing is done, I would like to know how it works.

And I want to redirect the user to the login.html page if he is not logged in.

Thanks!

+6
source share
2 answers

I assume javascript - docs introduction is good enough

  var currentUser = Parse.User.current(); if (currentUser) { // do stuff with the user } else { // show the signup or login page } 

This is copied from docs.

+5
source

You might want to check if the session is really valid. The user can log in, but the session may have expired (or a hacked account).

One way to achieve this is to query the object in Parse and catch catch 209. If it is caught, you can log out the user and bring the navigation controller back to the login screen.

Take a look at this answer.

+1
source

Source: https://habr.com/ru/post/975644/


All Articles