Meteor.user() nor returning all fields on client side

I’m using the accounts-UI and accounts-password package in the meteor. I’ve configured that package and able to insert the user data on DB using Accounts.createUser. So, In mongo, all the details stored properly. Please have a look at the mongo user document -

{
        "_id" : "CGafKmHTD8Kt4M4ak",
        "createdAt" : ISODate("2018-07-21T11:40:45.240Z"),
        "services" : {
                "password" : {
                        "bcrypt" : "$2b$10$Pg0qeQzNchUxfS/7r.yX1.qU1Qa8IrijOyvNuuFkNKGcZOt7k7Fhi"
                },
                "resume" : {
                        "loginTokens" : [
                                {
                                        "when" : ISODate("2018-07-21T11:42:38.914Z"),
                                        "hashedToken" : "3SqBs4sSBIsc6aiiOMR/2LbajNYPWC7/YsW32JmlEck="
                                }
                        ]
                }
        },
        "emails" : [
                {
                        "address" : "aaa@grepruby.com",
                        "verified" : false
                }
        ],
        "role" : "admin",
        "orgId" : "jWHb5Ea5ETcBzKwxW",
        "country" : "xxx",
        "zipCode" : "456090",
        "userName" : "111",
        "fullName" : "shubham akodiyaa",
        "city" : "in",
        "state" : "cv",
        "updatedAt" : ISODate("2018-07-21T11:42:38.915Z")
}

But at the client side using the Meteor.user(), I’m getting only the userId and email field. Could you please let me know the way to get all those details except the password ? and Is there any way to customize Meteor.user() publication ?

On client side Meteor.user() only returns fields that the client has access to. So you need to make a publication with the relevant fields and subscribe to it. You can do that the same way you deal with any other collection. For inspiration, look at the publication code provided here and replace ‘Rooms’ with ‘Meteor.users’: https://docs.meteor.com/api/pubsub.html#Meteor-publish

And be sure to only publish fields that you need to. https://docs.meteor.com/api/collections.html#fieldspecifiers

1 Like