I need to get name after user logged in via social network. But console.log(name) returns undefined. Why?
login() {
var that = this;
var vk = {
data: { user: { first_name: '', last_name: '', id: null } },
init: new Promise(function (resolve, reject) {
VK.init({ apiId: 6480684 });
load();
function load() {
VK.Auth.login(authInfo);
function authInfo(response) {
if (response.session) {
vk.data.user = response.session.user;
resolve();
} else {
reject();
}
}
}
})
}
async function data() {
await vk.init;
console.log('vk login');
that.name = vk.data.user.first_name + ' ' + vk.data.user.last_name;
that.id = vk.data.user.id;
that.db.object('users/' + vk.data.user.id).set({
id: vk.data.user.id,
displayName: that.name
});
}
data();
console.log(this.name);
}
After this function user added to database, but name is undefined.