The password authentication plugin is used to attach identity & password login to your application.
It does so by altering your account model, adding a password
field and the identity
field configured.
Behind the scenes, it uses bcryptjs to correctly hash user passwords.
npm i --save thorin-plugin-auth-password@1.x
'use strict'; // app.js entry file const thorin = require('thorin'); thorin.addPlugin(require('thorin-plugin-auth-password')); // <- add this line thorin.run((err) => {});
#update config/app.js with your configuration
# run to setup the models and module node app.js --setup=plugin.auth-password
loginAt
to false
to disable.
thorin.error
, otherwise return undefined
modelName
.
'use strict';
const storeObj = thorin.store('sql');
dispatcher
.addAction('account.login')
// The authorization will essentially add:
// input({
// user: dispatcher.validate('string'),
// password: dispatcher.validate('string')
// })
// and check the account matching the two.
.authorize('auth#password.login')
.use((intentObj, next) => {
const accountObj = intentObj.data('account');
log.info('Account logged in');
next();
});
{opt.password.field}
, {opt.password.field}_new
and {opt.password.field}_check
, check if they match
and finally update the account entity with the new password.
account
model be placed in the intent's data object
under the {opt.modelName}
key.
'use strict';
const storeObj = thorin.store('sql');
dispatcher
.addAction('account.password.change')
.use((intentObj, next) => {
const Account = storeObj.model('account');
// first read the accountObj that wants to change the password
Account.find({
where: {id: 1}
}).then((accObj) => {
// and place it under the "account" data field.
intentObj.data('account', accObj);
});
})
// The authorization will essentially add:
// input({
// password: dispatcher.validate('string'),
// password_new: dispatcher.validate('string'),
// password_check: dispatcher.validate('string')
// });
.authorization('auth#password.change')
.use((intentObj, next) => {
log.info('Password changed');
next();
});
Every time the user performs a login or changes his password, a auth:history
event is fired through
the dispatcher. For a more complex example, visit our examples.
You can always create a new issue on GitHub or contact one of the core founders by chat.