0

I am facing such a wired issue. i used JavaScript SDK to login in PARSE platform and successfully login. On the next page i am trying to get current user login using PHP SDK.

But strange no result coming, return NULL

What could be the issue ?

JavaScript:

Parse.User.logIn("myname", "mypass", {
  success: function(user) {
    // Do stuff after successful login.
  },
  error: function(user, error) {
    // The login failed. Check error to see why.
  }
});

PHP:

$currentUser = ParseUser::getCurrentUser();

Null Result here.

1 Answer 1

2

If you are login with Javascript you can access the current user using the following command:

Parse.User.current()

I don't thing that you can access the same user from PHP because you didn't login via the PHP SDK.

You have 2 options:

  1. Login the user via the PHP SDK using the following code (from parse php docs). This is the recommended approach since you are doing it on the server.

    try {
      $user = ParseUser::logIn("myname", "mypass");
      // Do stuff after successful login.
    } catch (ParseException $error) {
      // The login failed. Check error to see why.
    }

and then you will be able to access the current user like this:

$currentUser = ParseUser::getCurrentUser(); 
  1. Login with JavaScript SDK and access to user with Parse.User.current()

My POV

if your is already work with PHP what i think you should do is to use Parse PHP SDK on the PHP side and trigger the PHP functions from Javascript using ajax requests. There are some workaround solution that will allow you to have the current user on both sides (PHP and JavaScript) but then you will need to deal the current user session token and this can make your app a bit complicated.

So if you want to get the current user from PHP to JavaScript you can execute a ajax call to PHP and from PHP you can return the current user object or you can just do everything on the PHP side which is also fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.