[英]Meteor Js limiting access to my meteor app
我有一個流星應用程序,我想托管它,但是我只希望幾個人登錄並可以訪問它,最多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
的用戶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;
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.