How to use the meteor/meteor.Meteor.userId function in meteor

To help you get started, we’ve selected a few meteor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github okgrow / analytics / client / meteor-analytics.js View on Github external
const trackLogins = function trackLogins() {
  // Don't run on first time. We need to access Meteor.userId() for reactivity.
  Meteor.userId();
  if (initialized) {
    // When Meteor.userId() changes this will run.
    if (Meteor.userId()) {
      // TODO I think it's not guaranteed that userEmail has been set because
      // the 'AnalyticsUsers' publication might not be ready yet.
      identifyWhenReady(Meteor.userId(), { email: getUserEmail() });
      trackEventWhenReady("Signed in");
    } else {
      trackEventWhenReady("Signed out");
    }
  }
  initialized = true;
};
github RocketChat / Rocket.Chat / server / methods / createDirectMessage.js View on Github external
const me = Meteor.user();

		if (!me.username) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'createDirectMessage',
			});
		}

		if (settings.get('Message_AllowDirectMessagesToYourself') === false && me.username === username) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'createDirectMessage',
			});
		}

		if (!hasPermission(Meteor.userId(), 'create-d')) {
			throw new Meteor.Error('error-not-allowed', 'Not allowed', {
				method: 'createDirectMessage',
			});
		}

		const to = Users.findOneByUsername(username);

		if (!to) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', {
				method: 'createDirectMessage',
			});
		}

		if (!hasPermission(to._id, 'view-d-room')) {
			throw new Meteor.Error('error-not-allowed', 'Target user not allowed to receive messages', {
				method: 'createDirectMessage',
github paladinarcher / padawan / imports / api / users / methods.js View on Github external
newEmailArray.forEach((address) => {
                    Accounts.addEmail(Meteor.userId(), address);
                });
                //
github Blockrazor / blockrazor / imports / api / auctions / methods.js View on Github external
newAuction: (name, description, options) => {
		check(name, String)
		check(description, String)
		check(options, Object)

		if (Meteor.userId()) {
			let user = UserData.findOne({
				_id: Meteor.userId()
			})

			if (options.amount && user && (options.baseCurrency === 'KZR' ? user.balance : (user.others || {})[options.baseCurrency]) > options.amount && options.amount > 0) {
				if (options.timeout < new Date().getTime()) {
					throw new Meteor.Error('Error.', 'messages.auctions.past')
				}

				Auctions.insert({
				    name: name,
				    description: description,
				    options: options,
				    createdBy: Meteor.userId(),
				    createdAt: new Date().getTime(),
				    closed:false
github RocketChat / Rocket.Chat / app / lib / server / methods / createToken.js View on Github external
createToken(userId) {
		if (Meteor.userId() !== userId && !hasPermission(Meteor.userId(), 'user-generate-access-token')) {
			throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'createToken' });
		}
		const token = Accounts._generateStampedLoginToken();
		Accounts._insertLoginToken(userId, token);
		return {
			userId,
			authToken: token.token,
		};
	},
});
github Blockrazor / blockrazor / imports / api / hashing / methods.js View on Github external
hashPowerVote: function(hpId, type) {
        if (!Meteor.userId()) {
        	throw new Meteor.Error('Error.', 'messages.login')
        }

        let mod = UserData.findOne({
        	_id: this.userId
        }, {
        	fields: {
        		moderator: true
        	}
        })

        if (!mod || !mod.moderator) {
          	throw new Meteor.Error('Error.', 'mod-only')
        }
        
        let hp = HashPower.findOne({
github RocketChat / Rocket.Chat / app / livechat / server / methods / saveTrigger.js View on Github external
'livechat:saveTrigger'(trigger) {
		if (!Meteor.userId() || !hasPermission(Meteor.userId(), 'view-livechat-manager')) {
			throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveTrigger' });
		}

		check(trigger, {
			_id: Match.Maybe(String),
			name: String,
			description: String,
			enabled: Boolean,
			runOnce: Boolean,
			conditions: Array,
			actions: Array,
		});

		if (trigger._id) {
			return LivechatTrigger.updateById(trigger._id, trigger);
		}
github cleverbeagle / pup / ui / pages / Profile / Profile.js View on Github external
export default withTracker(() => {
  const subscription = Meteor.subscribe('users.editProfile');

  return {
    loading: !subscription.ready(),
    user: getUserProfile(Meteor.users.findOne({ _id: Meteor.userId() })),
  };
})(Profile);
github RocketChat / Rocket.Chat / packages / rocketchat-lib / server / functions / setUsername.js View on Github external
[0]() {
		return !Meteor.userId() || !hasPermission(Meteor.userId(), 'edit-other-user-info');
	},
});
github kromitgmbh / titra / imports / ui / pages / projectlist.js View on Github external
isProjectOwner(_id) {
    return Projects.findOne({ _id }) ? Projects.findOne({ _id }).userId === Meteor.userId() : false
  },
  colorOpacity(hex, op) {