basicauth.js 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. const AuthPrompt = require('../types/auth');
  3. function defaultAuthenticate(value, state) {
  4. if (value.username === this.options.username && value.password === this.options.password) {
  5. return true;
  6. }
  7. return false;
  8. }
  9. const factory = (authenticate = defaultAuthenticate) => {
  10. const choices = [
  11. { name: 'username', message: 'username' },
  12. {
  13. name: 'password',
  14. message: 'password',
  15. format(input) {
  16. if (this.options.showPassword) {
  17. return input;
  18. }
  19. let color = this.state.submitted ? this.styles.primary : this.styles.muted;
  20. return color(this.symbols.asterisk.repeat(input.length));
  21. }
  22. }
  23. ];
  24. class BasicAuthPrompt extends AuthPrompt.create(authenticate) {
  25. constructor(options) {
  26. super({ ...options, choices });
  27. }
  28. static create(authenticate) {
  29. return factory(authenticate);
  30. }
  31. }
  32. return BasicAuthPrompt;
  33. };
  34. module.exports = factory();