简体   繁体   中英

Cannot get the user details once the registration process is complete in MeteorJS

I am building a simple blog application using Meteor and ReactJS. And I'm using react-komposer to make it reactive. The issue I'm having is related to the user registration/Login process. accounts-base, accounts-password are the two Meteor packages I'm using to handle register & login functionalities.

Here's my LoginHeader component

import React from 'react';

const LoginRegister = () => (
    <div>
        <a href="/login" className="navbar-link">Login  | </a> 
        <a href="/register" className="navbar-link">Register </a>
    </div>
);

const LoginHeader = (user) => (
   <div>        
     <p className="navbar-text navbar-right">
        {user ? user.user.emails[0].address : <LoginRegister />}
     </p>       
   </div>
);

export default LoginHeader;

This is the LoginHeader container

import LoginHeader from '../components/login_header.jsx';
import {useDeps, composeAll, composeWithTracker, compose} from 'mantra-core';

export const composer = ({context}, onData) => {
  const {Meteor, Collections} = context();

  var user = Meteor.user();

  onData(null, {user});
};

export const depsMapper = (context, actions) => ({
  context: () => context
});

export default composeAll(
  composeWithTracker(composer),
  useDeps(depsMapper)
)(LoginHeader);

What's weired about it is that user.user.emails[0].address worked for a while and all of a sudden it started giving me the error Uncaught TypeError: Cannot read property 'emails' of undefined .

Help me to figure out what I'm doing wrong here.

Have had the same problem. Are you sure the user is loaded? See the following question:

What am I doing wrong when manipulating data in Meteor/MongoDB?

And make sure to find the sure path that Michel Floyd pointed out. Check the structure of your user collection in MongoDB.

如果user = Meteor.user()那么电子邮件地址是user.emails.address[0]而不是user.user...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM