so i want to show all of groups that user have when logged in. But i just got 1 value only. I'm still newbie using node js
so here the code :
var data = { id: user.id_panel_users, username: user.username, role: user.role, groups: user.groups }
var [group] = await modelGroup.getUserGroup(data.id)
for(let i=0;i<group.length;i++){
data.groups = group[i].group_name;
}
console.log(group, data.groups)
// data.toString();
console.log("serialize user: ", data)
done(null, data);
here the result :
[
TextRow { group_name: 'add_url_premium' },
TextRow { group_name: 'add_url_regular' }
] add_url_regular
serialize user: {
id: 77,
username: '082122735123',
role: 2,
groups: 'add_url_regular'
}
await modelGroup.getUserGroup(data.id), does it return an array of arrays, or just a single array? When you usevar [group] = ..., you expect the right-hand-side to return an array containing a single value, and you are assigning that value to thegroupvariable. This might be another source of the problem.