Created
February 10, 2021 14:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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