I'm using parse.com as a back end for a web app. I have a user that I have signed in to the app, and when the user is signed in to the website, I want their name to appear on every page in the website.
Here is my code for trying to recognize the username of the user:
// user logs on and is redirected to this page
var user = Parse.User.current();
user.on('change', function () {
console.log(user.get("username"));
});
user.fetch();
However, when I check the console, the error
Uncaught ReferenceError: user is not defined
is present.
In my research, I've modified the code from Unable to get User's data . However, in my case, this code is not working.
Any help is greatly appreciated!
Try this:
var user = Parse.User.current();
user.fetch().then(function(fetchedUser){
var name = fetchedUser.getUsername();
}, function(error){
//Handle the error
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.