Skip to content

Instantly share code, notes, and snippets.

@maiquealmeida
Created February 10, 2021 14:50
Show Gist options
  • Save maiquealmeida/0bb17117556735f89d71682173173055 to your computer and use it in GitHub Desktop.
Save maiquealmeida/0bb17117556735f89d71682173173055 to your computer and use it in GitHub Desktop.
Altera a senha de um usuario administrador do Strapi através do console.
// Altere o script e cole ele no console do strapi.
// npx strapi console
function changePassword(email, password) {
strapi.admin.services.user.findOne({ email: email }).then(user => {
if (user) {
strapi.admin.services.auth.hashPassword(password).then(hashedPassword => {
strapi.query('user', 'admin').update({ id: user.id }, { password: hashedPassword })
.then(() => console.log('Atualizado com sucesso.'))
.catch((err) => console.error('Erro ao atualizar a senha.', err))
}).catch(ex => console.error('Problema ao aplicar hash na senha e atualiza-la.', ex));
} else {
console.error('Não encontrei um usuario com este email.');
}
});
}
changePassword('usuario@email', 'novaSenha');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment