質問

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
});
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top