Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor currentUser

Using the node.js framework Meteor -

how come the currentUser variable is defined in a template such as here:

<template name="main_template">
  <div class="container">
  {{#if currentUser}}
  {{> add_player_form_template}}
  {{/if}}
  </div>
</template>

but when I call currentUser from the console, it's undefined:

enter image description here

however, Meteor.userId is defined:

enter image description here

why is this?

like image 671
Alexander Mills Avatar asked Feb 05 '15 01:02

Alexander Mills


People also ask

What is the meteor user () function for?

userId() import { Meteor } from 'meteor/meteor' (accounts-base/accounts_common.js, line 410) Get the current user id, or null if no user is logged in.

What is Meteor API?

Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.

What is the name of the package that provides basic user accounts functionality?

`accounts-base` This package is the core of Meteor's developer-facing user accounts functionality.


2 Answers

{{ currentUser}} is a helper in the main_template template.

In your client Javascript you'll need to define that helper method. Something like:

Template.main_template.helpers({
  currentUser: function() {
    return Meteor.userId();
  }
})

This may help too http://docs.meteor.com/#/basic/templates.

like image 163
for_ever Avatar answered Sep 21 '22 23:09

for_ever


{{ currentUser }} is a template helper that simply calls Meteor.user().

In the console, you need to call Meteor.user().

like image 42
Dan Dascalescu Avatar answered Sep 21 '22 23:09

Dan Dascalescu