防止为登录用户创建帐户 Meteorjs [英] Prevent Account Creation for loggedIn Users Meteorjs

查看:33
本文介绍了防止为登录用户创建帐户 Meteorjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止已登录用户在meteor中创建Account,例如在登录时调用Accounts.createUser?当Accounts.createUser被调用检测时,我可以通过Meteor.userId()吗?

How to prevent loggedIn users in creating Account in meteor such as calling Accounts.createUser when they are logged in? Can I pass Meteor.userId() when Accounts.createUser is called to detect?

推荐答案

您可以使用 Accounts.onCreateUser 中止帐户创建、添加字段等

You can use Accounts.onCreateUser to abort account creation, add fields, etc.

if (Meteor.isServer) {
  Accounts.onCreateUser(function (options, user) {
    if (Meteor.userId())
      throw new Meteor.Error(400, 'Already logged in!');

    return user;
  });
}

这篇关于防止为登录用户创建帐户 Meteorjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆