Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
How can I add a user with KeystoneJS if I don't have any users?

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: 'me@m.com',
    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.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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?

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda