Return custom user data from Meteor.loginWithPassword

Using the following code I am managing login on my site, however to keep things dry and not needing to have multiple mutation functions on my client-side for the user object, how can I return custom data in the user object within Metoer.loginWithPassword? (I have a subscription running for the custom data, but it’s obviously not ready until after the login…)

Example.

User.name

Meteor.loginWithPassword(username, password, function (error) {
        if (!error) {
            let authenticated = true;
            let user = Meteor.user(); //custom data like user.name isn't available and I need it
            dispatch(types.CONFIG_USER_AUTH, authenticated, user, "Login Success : Debug: #login");
        } else {
            console.log(error)
        }
    });
};

Have you tried storing your custom data in the user profile object? In your example you’re referencing user.name; name is usually stored in user.profile.name, and Meteor publishes the user profile field by default (along with username and emails).

I would be wary of storing data in the user.profile object without understanding and dealing with the potential consequences.

By default, user.profile may be updated by the user without any security checks. So, basically don’t put anything in user.profile that you don’t mind the user being able to change at will … or … ensure you use an appropriate deny rule on the server to disallow user changes.

Check out this section of the Meteor Guide for more information.