[英]Meteor Js limiting access to my meteor app
I have a meteor app and I want to host it, but I only want a few people to login to it and have access to it, at most 5 people. 我有一个流星应用程序,我想托管它,但是我只希望几个人登录并可以访问它,最多5个人。 How Do I accomplish that?
我该怎么做?
You can create 5 accounts like these: 您可以创建5个这样的帐户:
Meteor.startup(function () {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'xxxxx',
email: 'xxxx@xxxx.xx',
password: 'xxxxxxx',
profile: {}
});
...
}
});
And avoid possiblity to create new user: 并避免创建新用户的可能性:
AccountsTemplates.configure({
forbidClientAccountCreation: true,
});
You can block the creation of new users with: 您可以使用以下方法阻止创建新用户:
Accounts.config({ forbidClientAccountCreation : true });
Checking the number of users in Meteor.startup
will prevent creation of users when you restart you app and already 5 users have been created. 在重新启动应用程序时检查
Meteor.startup
的用户Meteor.startup
将阻止创建用户,并且已经创建了5个用户。
When 5 users have been created, you can throw an error in Accounts.onCreateUser
. 创建5个用户后,您可以在
Accounts.onCreateUser
引发错误。 onCreateUser is called every time a new user is about to be created. 每次要创建新用户时,都会调用onCreateUser。 Throwing the error will cancel user creation.
引发错误将取消用户创建。
if (Meteor.isServer) {
Meteor.startup(function () {
if (Meteor.users.find().count() >= 5)
Accounts.config({
forbidClientAccountCreation : true
});
});
Accounts.onCreateUser(function (options, user) {
var numberOfUsers = Meteor.users.find().count();
if (numberOfUsers >= 4) {
Accounts.config({
forbidClientAccountCreation : true
});
};
if (numberOfUsers >= 5)
throw new Meteor.Error(403, "Signup forbidden");
return user;
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.