Hi i have found the answer i just have to set the usrIdentity object along with the userName and loginName key value pair like
var userIdentity = {
userId: username,
displayName: username,
attributes: {
foo: "bar"
},
loginName : username,
userName : username
};