diff --git a/src/commands/generate.command.ts b/src/commands/generate.command.ts index 0f08b64a99..89cf2ce9c6 100644 --- a/src/commands/generate.command.ts +++ b/src/commands/generate.command.ts @@ -1,4 +1,5 @@ import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service"; +import { StateService } from "jslib-common/abstractions/state.service"; import { Response } from "jslib-node/cli/models/response"; import { StringResponse } from "jslib-node/cli/models/response/stringResponse"; @@ -6,7 +7,10 @@ import { StringResponse } from "jslib-node/cli/models/response/stringResponse"; import { CliUtils } from "../utils"; export class GenerateCommand { - constructor(private passwordGenerationService: PasswordGenerationService) {} + constructor( + private passwordGenerationService: PasswordGenerationService, + private stateService: StateService + ) {} async run(cmdOptions: Record): Promise { const normalizedOptions = new Options(cmdOptions); @@ -22,9 +26,12 @@ export class GenerateCommand { capitalize: normalizedOptions.capitalize, includeNumber: normalizedOptions.includeNumber, }; - const enforcedOptions = - await this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options); - const password = await this.passwordGenerationService.generatePassword(enforcedOptions[0]); + + const enforcedOptions = (await this.stateService.getIsAuthenticated()) + ? (await this.passwordGenerationService.enforcePasswordGeneratorPoliciesOnOptions(options))[0] + : options; + + const password = await this.passwordGenerationService.generatePassword(enforcedOptions); const res = new StringResponse(password); return Response.success(res); } diff --git a/src/commands/serve.command.ts b/src/commands/serve.command.ts index 9d692aab37..93c4e31f75 100644 --- a/src/commands/serve.command.ts +++ b/src/commands/serve.command.ts @@ -84,7 +84,10 @@ export class ServeCommand { this.main.cryptoService, this.main.apiService ); - this.generateCommand = new GenerateCommand(this.main.passwordGenerationService); + this.generateCommand = new GenerateCommand( + this.main.passwordGenerationService, + this.main.stateService + ); this.syncCommand = new SyncCommand(this.main.syncService); this.statusCommand = new StatusCommand( this.main.environmentService, diff --git a/src/program.ts b/src/program.ts index 1ff242723d..53d0ef5cb5 100644 --- a/src/program.ts +++ b/src/program.ts @@ -322,7 +322,10 @@ export class Program extends BaseProgram { writeLn("", true); }) .action(async (options) => { - const command = new GenerateCommand(this.main.passwordGenerationService); + const command = new GenerateCommand( + this.main.passwordGenerationService, + this.main.stateService + ); const response = await command.run(options); this.processResponse(response); });