Object is not rendering


#1

I will refer you to my question on Stack Overflow. Feel free to answer here or there, which ever is more convenient. I tried to copy and paste my question and the details, but it came out pretty messy on the meteor forum. Thanks!


#2

Hi Dave,

The code on stack overflow is somewhat confusing.

1.) I clearly advise against creating your own user-management. In particular never ever store plaintext-passwords in your collection
2.) This:

  var userName = username.value;
  var passWord = password.value;
  var firstName = firstname.value;
  var lastName = lastname.value;
  var emailAddress = emailaddress.value;
```

You do not show where username, password, etc. are declared, so it looks like your code-snipped is broken or not the code in your application. So try to use the real code in your application.

3.) Try to separate your problems. Is the insert in the Collection not working for you? Or is displaying data in the collection not working for you?

#3

The username and password are the “name” value within the html code. Inserting into the collection is working fine, but displaying data from the collection is not working properly. I’ve subscribed and published the collection “UsersList”. Not sure if I am even doing it correctly. I am coming from Java and diving into JavaScript and the Meteor framework, hopefully that bit of information helps.


#4

You have to create a helper for the dashboard template in order to display the users. So something like this ->

Template.dashboard.helpers({
    users:() => UsersList.find(),
});

#5

THANK YOU ERICK!! I figured it had something to do with helpers, it was just going about typing it correctly.

EDIT: Still not showing up. :frowning:

Apparently userName is undefined. I have no clue on how that could be possible.


#6

Also you might want to use accounts to handle user login because it’s not safe to store plaintext passwords. Here is a better example of how you can write your code.

// Get the user information from the form
    const user = {
      username: $('[name="username"]').val(),
      password: $('[name="password"]').val(),
      email: $('[name="emailaddress"]').val(),
      profile: {
        firstname: $('[name="firstname"]').val(),
        lastname: $('[name="lastname"]').val(),
      }
    }

// use the accounts-password package to handle the heavy lifting of
// creating a user.     
    Accounts.createUser(user, function(error){ 
       if(error) {
         console.log(error.reason); // find a better way to display the error to the user
       } else {
        // If no error that's when you can route to dashboard.
         Router.go('/dashboard');
       }
    });

And if you use the accounts-password package, it comes baked in with the currentUser helper function you are trying to use in the dashboard template.


#7

Okay, so in other words….don’t reinvent the wheel? Thanks! Are there any good resources on how I can truly understand JavaScript? So far, I don’t understand the whole language.