简体   繁体   中英

Is it possible to only allow vorpal commands after a user has provided correct details

I have a command that a user will provide their authentication details to and then once that is confirmed and valid, they can use any of the other commands.

Ideally I would like to go like this

$ app auth
  # User provides auth details
$ app another_command
  # Can now acces commands

However if a user tries to access another_command before signing in it should show them a message saying to run the auth command.

Whats the best way of doing this in Vorpal

I would just make an external method that would be called that does all of the heavy lifting, and throw it into the command.validate method on each Vorpal action.

Sometihng like this should get you started:

function authFunction() {
  return app.authenticated;
}

vorpal.command('foo')
  .validate(authFunction)
  .action(action);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM