Reputation: 11
Would really appreciate some help here. Been banging my head against the table for a couple hours now.
I’m trying to create a simple search function to search for usernames. My goal is to be able to search the usernames and eventually add the selected username to a “teams” collection.
I’ve tried easy-search but had no luck. I’m trying to user Accounts.FindUserByUsername now but I keep getting undefined. I have accounts-password installed, btw.
This is my code:
Server side:
Meteor.methods({
findUser: function (username) {
const user = Accounts.findUserByUsername(username)
return user
}
})
Client side:
Template.search.helpers(function() {
Meteor.call('findUser', 'username', findUserCallback)
})
function findUserCallback(error, username) {
console.log(username)
}
Template.search.events({
'submit .search'(event) {
event.preventDefault()
Meteor.call('findUser', 'username', findUserCallback)
}
})
I know I’m doing something very wrong but I can’t figure out what. I haven’t found much help online.
Thank you so much – I really appreciate it!
Upvotes: 0
Views: 254
Reputation: 7777
Welcome to Stack Overflow Julia.
The Meteor users collection is special, because it's used for authentication, and access to other users is not advisable in the UI, because of the security risks.
It is usual to have another collection called 'players' or 'members' - the advantage of this is that you can store additional information, and you can easily publish/subscribe to these collections and manipulate them without the need to be writing Meteor methods to do your work.
In the new collection you can store the _id of the user, so you can always reference the user record (ie for the username) if you need to.
Upvotes: 0