An easy way to obtain the first name


#1

Hi.

I created a custom field with user accounts with “first_name” and “last_name”: I want to obtain the first name in a email generated account, facebook account or gmail. How i can made that?

My layout code.

// Called by routes.js
import React from 'react';
import { createContainer } from 'meteor/react-meteor-data';

// Components
import TopMenu from '../components/header/top_menu';
import MainMenu from '../components/header/main_menu';

const MainLayout = (props) => (
  <div>
    <TopMenu user={props.user} userData={props.userData} first_name={props.first_name}/>
    <MainMenu />
    {props.main}
  </div>
);

export default createContainer(props => {
  userData = (!Meteor.user()) ? null : Meteor.user();
  first_name = function() {
    if (userData) {
      if (userData.profile.first_name) {
        return userData.profile.first_name;
      }
      else if (userData.services.facebook.first_name) {
        return userData.services.facebook.first_name;
      }
      else if (userData.services.google.first_name) {
        return userData.services.google.first_name;
      }
      else return 'error';
    }
    else return 'Cargando ...';
  }
  return {
    user: Meteor.userId(),
    userData: userData,
    first_name: first_name()
  };
}, MainLayout);

I’m search for an easy way to obtain the first name.

Thanks :slight_smile: