Meteor-feature-requests: allow override default user publish fields without autopublish package

Created on 31 Jan 2018  路  5Comments  路  Source: meteor/meteor-feature-requests

i want to add some other fields that comes with the default account publish null in a package, but addAutopublishFields only works with autopublish enabled.

https://github.com/meteor/meteor/blob/devel/packages/accounts-base/accounts_server.js#L31

https://github.com/meteor/meteor/blob/devel/packages/accounts-base/accounts_server.js#L740

write this in package will cause tacker rerun two times

Meteor.publish(null, function () {
  if (!this.userId)
    return

  return Meteor.users.find({ _id: this.userId }, { fields: { [CROSS_ACCOUNTS_FIELD]: true } })
})

image

image

Accounts (in user apps)

Most helpful comment

can we just allow this without adding autopublish package ?

Accounts.addAutopublishFields({
  forLoggedInUser: [otherFields],
})

All 5 comments

can we just allow this without adding autopublish package ?

Accounts.addAutopublishFields({
  forLoggedInUser: [otherFields],
})

@crapthings correct me if I'm wrong, but I think this feature has been implemented:

Accounts.addAutopublishFields({
  forLoggedInUser: ['createdAt', 'secret'],
  forOtherUsers: ['createdAt'],
})
Accounts.onCreateUser(({ password, ...option }, user) => ({ ...option, ...user }))

Accounts.addAutopublishFields({
  forLoggedInUser: ['hello'],
  forOtherUsers: ['hello'],
})

Meteor.publish('currentUser', function () {
  return Meteor.users.find({ _id: this.userId }, { fields: { services: false } })
})

Meteor.startup(function () {
  if (Meteor.users.findOne()) return
  Accounts.createUser({ username: 'demo', password: 'demo', hello: 'kitty' })
})

image

@StorytellerCZ still doesn't work.

the solution for now

i start a 'currentUser' subscribe and wait for its ready after user login.
there will be two ddp messages send, one from accounts its self(publish null), and the subscribe one.

1. Meteor.userId() && !Meteor.loggingIn()
2. Meteor.subscribe('currentUser').ready()
3. render UI

if addAutopublishFields works, i can remove the extra subscribe

Check the defaultFieldSelector option of Accounts.config

it looks the defaultFieldSelector doesn't override by config

Accounts.config({
  defaultFieldSelector: { hello: 1 }
})
Accounts.config({
  defaultFieldSelector: { fields: { hello: 1 } }
})
Accounts.config({
  defaultFieldSelector: { projection: { hello: 1 } }
})

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cunneen picture cunneen  路  5Comments

mitar picture mitar  路  5Comments

stolinski picture stolinski  路  3Comments

msavin picture msavin  路  3Comments

lamhieu-vk picture lamhieu-vk  路  4Comments