Meteor Js 限制访问我的流星应用程序
Meteor Js limiting access to my meteor app
我有一个 meteor 应用程序,我想托管它,但我只希望几个人登录并访问它,最多 5 个人。我该如何实现?
您可以像这样创建 5 个帐户:
Meteor.startup(function () {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'xxxxx',
email: 'xxxx@xxxx.xx',
password: 'xxxxxxx',
profile: {}
});
...
}
});
并避免创建新用户的可能性:
AccountsTemplates.configure({
forbidClientAccountCreation: true,
});
您可以通过以下方式阻止创建新用户:
Accounts.config({ forbidClientAccountCreation : true });
检查 Meteor.startup
中的用户数量将在您重新启动应用程序时阻止创建用户,并且已经创建了 5 个用户。
当创建了 5 个用户后,您可以在 Accounts.onCreateUser
中抛出错误。每次要创建新用户时都会调用 onCreateUser。抛出错误将取消用户创建。
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;
});
}
我有一个 meteor 应用程序,我想托管它,但我只希望几个人登录并访问它,最多 5 个人。我该如何实现?
您可以像这样创建 5 个帐户:
Meteor.startup(function () {
if (Meteor.users.find().count() === 0) {
Accounts.createUser({
username: 'xxxxx',
email: 'xxxx@xxxx.xx',
password: 'xxxxxxx',
profile: {}
});
...
}
});
并避免创建新用户的可能性:
AccountsTemplates.configure({
forbidClientAccountCreation: true,
});
您可以通过以下方式阻止创建新用户:
Accounts.config({ forbidClientAccountCreation : true });
检查 Meteor.startup
中的用户数量将在您重新启动应用程序时阻止创建用户,并且已经创建了 5 个用户。
当创建了 5 个用户后,您可以在 Accounts.onCreateUser
中抛出错误。每次要创建新用户时都会调用 onCreateUser。抛出错误将取消用户创建。
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;
});
}