Adding new fields on Third Party Account creation


I am using the user-accounts package to manage the Account System in my app.

I have also integrated Google, Github, Twitter and other 3rd party Services.

The package works fine, but now that I need a specific page for every user, and for SEO terms, I need the url to be like this:

I also have the accounts-password package. And I have added a username field, and it works fine.

But if thirdparty services are used, the popup closes and the page is redirected with the user successfully created. I read about calling Accounts.onUserCreate,
and this is my code:

Accounts.onCreateUser(function(options, user) {
  var email =;
 var ist = email.indexOf("@");
 var uname = email.slice(0,ist);
 user.username = uname;
user.profile = options.profile;
  return user;

But it gives an error : Cannot read indexOf of undefined.

How can this be achieved?

There either can be a page, to enter the username, for every new user, or this way, the email should be sliced for username creation. (Second method is preferred.)