Reputation: 11
Sorry if this is an incredibly basic question but I can not find any helpful information out there.
I used the yeoman keystone generator to create a keystone project but MongoDB wasn't working when I ran the generator so the user didn't get created. I can not find any information on how to add the user.
Here is what I tried:
I added this to the routes/views/index.js file so it would get executed when the page loads:
var user = new User({
name: { first:'matt', last:'x' },
email: '[email protected]',
password: 'password',
isAdmin: true
});
user.save(function (err) {
if (err) {
// handle error
return console.log(err);
}
// user has been saved
console.log(user);
});
This added a user to the database, but I get this error when I try to login:
Sorry, an error occurred loading the page (500)
Must supply api_key
How do I resolve this?
Thanks for any help.
Upvotes: 0
Views: 795
Reputation: 3218
Use the built-in update functionality to add a new user. Add this code to an updates/0.0.2-admins.js
file:
var keystone = require('keystone'),
User = keystone.list('User');
exports = module.exports = function(done) {
new User.model({
name: { first: 'Admin', last: 'User' },
password: 'admin',
isAdmin: true
}).save(done);
};
Can you post the full error regarding your API key, though?
Upvotes: 2