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 foo@bar.com 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]

2 Likes

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 http://docs.meteor.com/#/full/accounts_ui_config, 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.

2 Likes

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 jcarson@gmail.com and jcarson@yahoo.com?
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:

1 Like

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 sashko@meteor.com and another to have sashko@gmail.com, 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.

1 Like

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 {this.data.currentUser.username}!</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 this.data.currentUser.username? 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

1 Like

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.