Hi! I’m having trouble with this seemingly trivial stuff, harrrr!
I have this user document:
userData = {
account: {
type: 'free'
},
profile: {
name: 'Artem',
},
username: 'aaa@gmail.com',
password: '123'
};
Which I’m sending client-side: Accounts.createUser(userData);
Then server side I want to check if account type equals ‘free’. If it doesn’t - I want to abort new user creation (and hopefully throw error client side)
There are 2 functions which I’ve found in the docs that presumably can help me do it:
-
Accounts.validateNewUser
Problem: it receives ‘trimmed-down’ user object which doesn’t contain properties other thanprofile, username, password, email
. Thus I cannot validateaccount.type
as it doesn’t exist on user object being validated. -
Accounts.onCreateUser
Problem: it is called after a generic user object is created and there is no way I can cancel inserting new document in Users collection. It absolutely requires to return a user document. If I returnundefined
it throws errors on server:
Exception while invoking method 'createUser' Error: insert requires an argument
It also doesn’t allow to throw method errors (as it’s not a method) -> thus I cannot log error client side.