password.js 497 B

1234567891011121314
  1. 'use strict';
  2. module.exports = () => {
  3. return async function password(ctx, next) {
  4. // mongodb中secret转换为密码类型
  5. const method = ctx.request.method;
  6. const isLoginEnd = ctx.request.url.includes('login');
  7. const passwordNoDeal = ctx.request.headers.passwordnodeal;
  8. if (method !== 'GET' && !isLoginEnd && !passwordNoDeal) {
  9. const body = ctx.request.body;
  10. if (body && body.password) body.password = { secret: body.password };
  11. }
  12. await next();
  13. };
  14. };