|
@@ -1,23 +1,24 @@
|
|
|
-Accounts.registerLoginHandler(function (loginRequest) {
|
|
|
- Meteor._debug("Server registerLoginHandler", loginRequest);
|
|
|
+Accounts.registerLoginHandler("adminHandler", function (loginRequest) {
|
|
|
+ Meteor._debug("Server registerLoginHandler, request", 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);
|
|
|
+ result = undefined;
|
|
|
+ Meteor._debug("Server registerLoginHandler for non-admin, returning", result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
// Our authentication logic.
|
|
|
- if (loginRequest.password.password !== "admin-password") {
|
|
|
- result = null;
|
|
|
- Meteor._debug("Server registerLoginHandler, returning", result);
|
|
|
+ if (loginRequest.password !== "admin-password") {
|
|
|
+ result = { error: new Meteor.Error(400, "Incorrect password") };
|
|
|
+ Meteor._debug("Server registerLoginHandler for bad password, returning", result);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ Meteor._debug("Server registerLoginHandler for good password, continuing");
|
|
|
// We create an admin user if none exists, and get its userId.
|
|
|
let userId;
|
|
|
let user = Meteor.users.findOne({ username: "admin" });
|
|
@@ -29,8 +30,8 @@ Accounts.registerLoginHandler(function (loginRequest) {
|
|
|
}
|
|
|
// Send logged-in user's id.
|
|
|
result = {
|
|
|
- id: userId
|
|
|
+ userId: userId
|
|
|
};
|
|
|
- Meteor._debug("Server registerLoginHandler, returning", result);
|
|
|
+ Meteor._debug("Server registerLoginHandler allowed, returning", result);
|
|
|
return result;
|
|
|
});
|