|
@@ -0,0 +1,36 @@
|
|
|
+Accounts.registerLoginHandler(function (loginRequest) {
|
|
|
+ Meteor._debug("Server registerLoginHandler", loginRequest);
|
|
|
+ // There are multiple login handlers in Meteor.
|
|
|
+ // A login request goes through all these handlers to find its login handler.
|
|
|
+ // So in our login handler, we only consider login requests which have an
|
|
|
+ // "admin" field.
|
|
|
+ let result;
|
|
|
+ if (!loginRequest.admin) {
|
|
|
+ result = void 0;
|
|
|
+ Meteor._debug("Server registerLoginHandler, returning", result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Our authentication logic.
|
|
|
+ if (loginRequest.password.password !== "admin-password") {
|
|
|
+ result = null;
|
|
|
+ Meteor._debug("Server registerLoginHandler, returning", result);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // We create an admin user if none exists, and get its userId.
|
|
|
+ let userId;
|
|
|
+ let user = Meteor.users.findOne({ username: "admin" });
|
|
|
+ if (!user) {
|
|
|
+ userId = Meteor.users.insert({ username: "admin" });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ userId = user._id;
|
|
|
+ }
|
|
|
+ // Send logged-in user's id.
|
|
|
+ result = {
|
|
|
+ id: userId
|
|
|
+ };
|
|
|
+ Meteor._debug("Server registerLoginHandler, returning", result);
|
|
|
+ return result;
|
|
|
+});
|