I am able to login with user credentials with
try {
$user = ParseUser::logIn("myname", "mypass");
// Do stuff after successful login.
} catch (ParseException $error) {
// The login failed. Check error to see why.
}
but if I try to get the currentUser afterwards with
$currentUser = ParseUser::getCurrentUser();
if ($currentUser) {
// do stuff with the user
} else {
// show the signup or login page
}
$currentUser is not set.
I suspect this more to be a php "issue" that I don't know. I am greatful for any hint for keeping currentUser retained in my code as long I do not log out.
In order for the getCurrentUser() method to work, you must define the type of session storage to use. You can use the ParseSessionStorage class to achieve this:
use Parse\ParseClient;
use Parse\ParseUser;
use Parse\ParseSessionStorage;
session_start();
// Init parse: app_id, rest_key, master_key
ParseClient::initialize('xxx', 'yyy', 'zzz');
// set session storage
ParseClient::setStorage( new ParseSessionStorage() );
try {
$user = ParseUser::logIn("myname", "mypass");
// Do stuff after successful login.
} catch (ParseException $error) {
// The login failed. Check error to see why.
}
$currentUser = ParseUser::getCurrentUser();
print_r( $currentUser );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With