Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

userId with collection-hooks #92

Open
HBCharles opened this issue Mar 26, 2017 · 4 comments
Open

userId with collection-hooks #92

HBCharles opened this issue Mar 26, 2017 · 4 comments
Labels

Comments

@HBCharles
Copy link

Is there any possibility to have access in meteor methods to the userid of the account authenticated ? as in the following repo https://github.com/orionsoft/apollo-meteor/

I need it especially because i'm using that package matb33:collection-hooks

const Project = new Mongo.Collection('Project');

Project.before.insert(function(userId, doc) {
	doc.createdAt = new Date();
	doc.modifiedAt = new Date();
	doc.owner = userId // Doesn't works
});

Thanks

@lorensr
Copy link
Contributor

lorensr commented Mar 29, 2017

Why not use Meteor.userId() for methods?

Don't know where collection-hooks gets the userId from, but if ^ works in methods, I would imagine collection-hooks should also work.

@HBCharles
Copy link
Author

Just tried with Meteor.userId() and obtained the following error message :

Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.
    at AccountsServer.userId (packages/accounts-base/accounts_server.js:82:13)
    at Object.Meteor.userId (packages/accounts-base/accounts_common.js:257:19)
    at Object.<anonymous> (server/collections/projects/project.js:12:22)
    at packages\matb33_collection-hooks.js:352:26
    at Array.forEach (native)
    at Function._.each._.forEach (packages\underscore.js:139:11)
    at Object.<anonymous> (packages\matb33_collection-hooks.js:351:9)
    at Object.collection.(anonymous function) [as insert] (packages\matb33_collection-hooks.js:146:21)
    at [object Object].insert (packages/mongo/collection.js:521:37)

this.userId is undefined

@lorensr
Copy link
Contributor

lorensr commented Apr 19, 2017

Yeah, not sure why this package

https://github.com/matb33/meteor-collection-hooks

might be not accurately passing the userId arg to its hooks.

jamiter added a commit to Swydo/ddp-apollo that referenced this issue Feb 26, 2018
And also collection hooks and other places people expect a userId. This is very important for Meteor developers, especially when using the default mongo and accounts packages.

See apollographql/meteor-integration#92 for discussion.
jamiter pushed a commit to Swydo/ddp-apollo that referenced this issue Feb 26, 2018
And also collection hooks and other places people expect a userId. This
is very important for Meteor developers, especially when using the
default mongo and accounts packages.

See apollographql/meteor-integration#92 for
discussion.
@jamiter
Copy link

jamiter commented Feb 26, 2018

I know this ticket is almost a year old, but I like to mention this is available out of the box in https://github.com/Swydo/ddp-apollo, because it uses methods and publications under water 👍

@lorensr lorensr changed the title UserId in methods userId with collection-hooks Aug 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants