If you're in search of the additional option for a profile when utilizing Accounts.createUser(), make sure to refer to the documentation for detailed instructions on how to implement it: .
The profile feature requires an object that will be added to the database document linked with the user. Once you've tested the example below, execute the following commands to confirm that it has been stored in the database.
Within your project directory:
$ meteor mongo
$ db.users.find()
A sample output might look like this:
{ "_id" : "kJNaCtS2vW5qufwJs", "createdAt" : ISODate("2015-05-11T20:50:21.484Z"), "services" : { "password" : { "bcrypt" : "$2a$10$LrcZ5lEOlriqvkG5pJsbnOrfLN1ZSCNLmX6NP4ri9e5Qnk6mRHYhm" }, "resume" : { "loginTokens" : [ { "when" : ISODate("2015-05-11T20:50:21.493Z"), "hashedToken" : "CXKwUhEkIXgdz61cHl7ENnHfvdLwe4f0Z9BkF83BALM=" } ] } }, "emails" : [ { "address" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfccd7decdd4ddc6cbdaffccd0d2dadad2ded6d391dcd0d2">[email protected]</a>", "verified" : false } ], "profile" : { "firstName" : "shark", "lastName" : "byte" } }
Please note that I am not using accounts-ui, only accounts-password without the built-in UI. However, here's a guide on creating a basic account creation template with extra fields (such as first & last name, and organization).
HTML code:
<head>
<title>test</title>
</head>
<body>
<!-- checks if someone is logged in -->
{{#if currentUser}}
{{> userPage}}
{{else}}
{{> loginPage}}
{{/if}}
</body>
<template name="userPage">
<button id="logout">logout</button>
<p>You are logged in!</p>
</template>
<template name="loginPage">
<form><!-- create account form, use a different one for normal logging in -->
<input type="text" id="firstName" placeholder="First Name">
<input type="text" id="lastName" placeholder="Last Name">
<input type="text" id="organization" placeholder="Organization (optional)">
<input type="text" id="email" placeholder="Email Address">
<input type="password" id="password" placeholder="Password">
<input type="password" id="confirmPassword" placeholder="Confirm Password">
<input type="submit" id="createAccount" value="Create Account">
</form>
</template>
Javascript code:
if (Meteor.isClient) {
Template.loginPage.events({
'submit form': function(event, template) {
event.preventDefault();
console.log('creating account');
var passwordVar = template.find('#password').value;
var confirmVar = template.find('#confirmPassword').value;
if (passwordVar === confirmVar) {
Accounts.createUser({
email: template.find('#email').value,
password: passwordVar,
// you can add wherever fields you want to profile
// you should run some validation on values first though
profile: {
firstName: template.find('#firstName').value,
lastName: template.find('#lastName').value
}
});
}
}
});
// ensure there is a logout button
Template.userPage.events({
'click #logout': function(event, template) {
Meteor.logout();
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}