Meteor Accounts.createUser is not a function - meteor

Whenever I try to call "Accounts.createUser" (on the client) I get "EXCEPTION: TypeError: Accounts.createUser is not a function".
Accoridng to the documentation it should work "By default, the Accounts.createUser function provided by accounts-password allows you to create an account with a username, email, or both."https://guide.meteor.com/accounts.html#requiring-username-email
I added
meteor add accounts-base
meteor add accounts-password
My Code:
import {Accounts} from 'meteor/accounts-base';
Accounts.createUser({
username: 'TestUser01',
email: 'TestUser01#test.de',
password: 'string'
}, function (err) {
if (err)
console.log(err);
else
console.log('It worked...');
});
EDIT: As a info, I want to have it client side. Server side works fine for me.

Related

Not able to login - User has no password set

I don't want to use accounts-ui or accounts-ui-unstyled, only accounts-password, thus I decided to use the Accounts and Meteor methods.
I create a user with the following code (client):
Accounts.createUser({
email: email,
emails: [{address: email, verified: false}],
password: password,
profile: {
name: name
}
}, function(err) { ... });
which seems to be working fine, however when I try to create do a login with this code (client):
Meteor.loginWithPassword(username, password, function(err){
console.error(err);
});
Doesn't matter if the password is correct or not it always replies: Error: User has no password set [403].
Meteor version: 1.4.2.3

Trying to publish users in Meteor

I'm quite new in Meteor and I got an issue: I added some information to users and I'd like to be able to see it in a view.
So I create my users, here is my event:
Accounts.createUser({
username: username,
email: email,
password: password,
firstname:firstname,
lastname:lastname,
chief:chief
},
function(error){
if(error){
alert(error.reason)
}else{
Router.go('home');
}
});
Accounts.onCreateUser(function(options,user){
user.firstname = options.firstname;
user.lastname = options.lastname;
user.chief = options.chief;
return user;
});
then I publish my collection to get access on my client side of the app:
Meteor.publish("personaldata", function () {
return Meteor.users.find({_id: this.userId});
});
And without doing anything else I got an issue on my app: there is no error message on my command prompt, but when I open my app I got an Ironn:Router message. Here is the message:
'organize your application'
Router.route('/', function () {
this.render('Home', {
data: function () {
return Items.findOne({_id: this.params._id});
}
});
});
Yes the whole part is the message. I tried to subscribe to the collection in 'home' to settle the issue but it doesn't work, the same message is displayed.Does someone know why this message is displayed ? How can I have access to those data? Isn't it the proper way?
Hope you guys can figure out what the problem is, thanks.
Found the problem...
As I'm stupid I put my publish in the lib directory, so this was on both the server and the client side... Meteor didn't know what to do with it on the client side.

No response from Jquery validation when creating Meteor account

Basically, I'm using Jquery validation package as a way to alert errors to users when creating and registering accounts on Meteor, since the boilerplate interface doesn't work in my case.
Anyway, when a user tries to sign up for an account, I get no response at all on client. The user is just created with no message or redirection like it's supposed to have.
Here is the particular code:
Template.createAccount.onRendered(function(){
var validator = $('.register').validate({
submitHandler: function(){
user = {
email: document.getElementById("email").value,
password: document.getElementById("password").value
};
Accounts.createUser({
email: user.email,
password: user.password,
function(error){
if(error){
if(error.reason == "Email already exists."){
validator.showErrors({
email: "The email belongs to a registered user."
});
}
} else{
console.log("Account successfully created.");
Router.go("starter");
}
}
});
}
});
})
I'm using the same code logic for account logins with the only exception being a different meteor accounts function (Meteor.loginWithPassword() for login and Accounts.createUser() for account creation).
No response at all, so it probably has to do something with the callback function, since the user account is created, but no message displayed on client.
You're including your callback as part of your options object when it should be a separate argument. It should look more like this:
Accounts.createUser({
email: user.email,
password: user.password
}, function(error){
if(error){
if(error.reason == "Email already exists."){
validator.showErrors({
email: "The email belongs to a registered user."
});
}
} else{
console.log("Account successfully created.");
Router.go("starter");
}
});

Accounts.createUser() is returning undefined on client

I have a SignUp/SignIn Process on my meteor site. I have a form to register new users and a form to login users.
I init users on serverside via
Accounts.createUser({username: "myusername", password: "mypassword"});
and I can login into my dummyusers via my loginform on the client with
Meteor.loginWithPassword(username, password)
I dont know why but for some reason I canĀ“t create new users on clientside. If I call
Accounts.createUser({username: username, password: password});
it returns undefined (safari)
I checked the input strings (username, password) and its not generating the error even pure strings like
Accounts.createUser({username: "test", password: "pass"});
returns undefined on client console.
I published and subscribed my users via:
Server
Meteor.publish('users', function () {
console.log("Server Log: publishing all users");
return Meteor.users.find();
});
Client
Meteor.subscribe("users");
I also can count() users on the client console but I cant use Accounts.createUser() so the createUser() function is not even working in my console.
Why I cant use Accounts.createUser() on client/console?
Accounts.createUser is an asynchronous function on the client because it needs to query the server to know if it actually succeeded (the username or email could already be in use). The return value of an asynchronous function will always be undefined, so the result is expected.
If you start with an empty project and an empty database, you could do:
Accounts.createUser({username: 'dave', password: 'password'});
which will return undefined, however a subsequent call to Meteor.userId() should return a string.
In order to determine if the call succeeded, you will need to supply a callback:
Accounts.createUser({username: 'dave', password: 'password'}, function(err) {
if (err)
console.log(err);
else
console.log('success!');
});

Sending verification email with Meteor causing error

I have the following:
Template.joinTemplate.events({
"submit #Signup-Form": function(event, template) {
event.preventDefault();
var email = template.find('#Email').value;
Accounts.createUser({
username: template.find('#Email').value,
emails: {
address: template.find('#Email').value
},
password: template.find('#Password').value,
profile: {
firstname: template.find("#Firstname").value,
lastname: template.find("#Lastname").value
}
}, function(error) {
if (error) {
// Deal with errors
} else {
Accounts.sendVerificationEmail(this.userId, email);
Router.go('/');
}
});
}
});
But get the following error:
Error logging in with token: Error: You've been logged out by the server. Please login again. [403] debug.js:41
Exception in delivering result of invoking 'createUser': TypeError: Object #<Object> has no method 'sendVerificationEmail'
at http://localhost:3000/client/views/application/authentication/join_template.js?0ca175e5dc0f3b4596ed33e260d5636f8f9cc69b:28:26
at http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:801:19
at loggedInAndDataReadyCallback (http://localhost:3000/packages/accounts-base.js?efdcc57c69f7e2ccbb61f1e963da216b1729ac72:455:5)
at null._callback (http://localhost:3000/packages/meteor.js?2b578107b8239ff9bc64200e6af2a24001461b30:801:22)
at _.extend._maybeInvokeCallback (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3502:12)
at _.extend.receiveResult (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3522:10)
at _.extend._livedata_result (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:4452:9)
at onMessage (http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:3376:12)
at http://localhost:3000/packages/livedata.js?418d88f2513ae6bf0ff1447759a5c590923456bd:2705:11
at Array.forEach (native)
I have all accounts-base, accounts-ui, accounts-password installed.
Not sure what I'm doing wrong :(
As you can read in the documentation, Accounts.sendVerificationEmail is only available on the server, and you're trying to use it on the client.
I'm not sure that you can use the Accounts.onCreateUser function to send verification emails: in this function, the user has not been added to the Meteor.users collection yet, and I guess Accounts.sendVerificationEmail requires the user to be in that collection. I don't know the best way to solve this, but you can always use a cursor selecting all users, and then observe users added to the collection (although, this is not a good solution).
It's not enough to use the sendVerificationEmail field in the Accounts.config function?

Resources