Email Login Package Bug


I used {{loginButton}} for login. When I sign up with email and password, the login usename returns nil. That is unexpected. If I has registered in the user name should be foo which is extracted from email.


Yeah… before you go pointing out that core Meteor code which has worked for everyone else is bugged, I’d suggest you hook onto the onCreateUser callback and see what’s going on under the hood :wink:

In this particular case, I’m pretty sure the username is not set for you and you have to grep it for yourself. I remember having to do this. Didn’t find any mention of setting username from email the source either.

Something like email.Match(/(^.+?)@/)[0]


Agree with @mordrax, what you are describing is not intended behavior for for accounts-password. Since you are using login buttons which is part of accounts-ui, you can optionally set the login buttons to display a field for the user to choose a user name. Have a look at, the passwordSignupFields option in particular. If you are dead set on bisecting it from the email address then @mordrax’s suggestion is likely what you need.


From user experience, when I have signed up with an email, I am going to expect a user name has been set as email or email name but not an empty as default. Otherwise user will be weird to get an empty username after signup.

In my case I waste time to figure out why the username of Meteor.user() is empty. This can be avoid in the future. Sure I can call it a glitch. But why afraid call it a bug? As a developer I love bug. I’d be happy for somebody to point a bug in my code. I do not care of calling it a bug or a glitch. If that is designed as intentional, what I can say is unnatural.


Not necessarily, if I set a email/password, I expect to just have an email/password. If I use Google login, I expect to only have the OAuth token. In other words, I expect default configuration.

How are you going to handle and
Will the second user ‘expect’ to be given jcarson2 as their username? Or will you make usernames non-unique.

The best advice I can give you is to read the manual. Even if it doesn’t behave as expected, it doesn’t say anything about programatically assigning arbitrary fields onUserCreation.
The second best advice is then to test it out. If you had seen there was no username, but then hooked into OnCreateUser and put a username in and saw it saved, then you would logically (and correctly) deduce it’s just not working as you intended.

In this case, I think the glitch/bug is between the chair and the keyboard my friend :smile:


There’s a simple reason why you can’t generate the username from an email address: the username part of an email isn’t unique. It would be easy for one person to have and another to have, and then only one of them would be able to register for your website since the username is unique.

I would suggest not adding a username field to your document, and instead either using the entire email address as a username (since it is unique), or having a UI helper that shows the username part in the UI.


I agree that it will make extra processing by using email head as user name. That is not a good solution.
In fact many real systems set user name as entire email address after signed up. This is a solution.

The argument is that whether the nil user name after signed up is a problem. The question did not come from nowhere.

Below is the simplest Hello example of React in Meteor Guide:

var HelloUser = React.createClass({
  mixins: [ReactMeteorData],
  getMeteorData() {
    return {
      currentUser: Meteor.user()
  render() {
    return <span>Hello {}!</span>;

I simply add a template and loginButtons to test this example.
What is the display after I signed up an account and logged in?

Hello !

What is the value of nothing.
What is wrong? I do not know. It can be my settings or something else.
I do not expect username will be nil here. I found that by using emails
instead of username there is a valid value. That is the confusion.
The nil username can be anything or nothing. It is the source of bugs.

Developers can review this case and figure out what the problem and solution is.
Document, Coding, API, Default settings, …

I have presented my solution.


I would vote for dropping “username” from whole MDG source and force people to use userId or user object instances, as it just create confusion. Forcing people to generate just another unique identifier as if the 1 we have was not enough already…
And the only reason I see to use it is cause in good old times it was needed…
I just dont see any logical explanation to use something like that in current age and forced unique…


Why don’t you just ask the user to provide their name on signup, as well as their email if you want to show their name…

The issue is that the account username field needs to be 100% unique as it can be used to login too… (as sashko said)

Your suggestion to make the username the persons email is superfluous, why not just display the email address already stored in the database? With: user().emails[0].address


I agree with you. It is an extra requirement to have two more unique id. However login package can assign a random unique id as user name after signed up.


Minimum user input info is a goal of signup. user-name is not user-id there is no unique requirement for any database system.

The point is that before the signup username is nil, but after the signup you still keep it as nil, how do you explain the common sense meaning of username? You just login as a no name.