3

I am creating command line interface by using node.js. It has login feature and after login, needs to show output based on user selection from list. Problem i'm facing is it exits from the node after first result. It's asking login again. It should not exit, if exit from app also fine but, still i should able to fetch the logged in user detail. Say example it displays user details when I selects Show user profile from the list. Now, I exit from app(not from the cli console). Again i have to login to see other result. Instead of that can we maintain any session kind of thing for the logged in user so that we can allow user to enter into system without login again and again. Or suggest me any other solution to do this. enter image description here! enter image description here

Sorry for my bad English. Hope you understand my problem. (attached an image)

I am using inquirer for user inputs, commander for help and request for HTTP operations. I can share my code if needed.

iLaYa ツ
  • 3,941
  • 3
  • 32
  • 48
  • Is it necessary that you *exit* from the app? Can't you just repeat the process? – laggingreflex Jul 01 '15 at 11:16
  • exit from the app is fine but, I logged in already, so its going to login again. can we do anything for maintaining user presence? – iLaYa ツ Jul 01 '15 at 11:19
  • Sorry, I thought you *needed* to exit from the app but I guess you don't. In which case I think the solution would be to simply *not exit* from the app, i.e. by **repeating** the step of asking the user to select an option again, sort of in a loop (and possibly adding an option to exit). That's what you want right? – laggingreflex Jul 01 '15 at 11:21
  • Exactly. OK, I can repeat the list. Suppose I exit from the app? Should we need to login again? can't we maintain logged in status for at-least few min? – iLaYa ツ Jul 01 '15 at 11:27
  • Maybe save the login credentials to JSON locally? Depending how secure you need this to be, if raw text works for you, great. If not, then you have to look into encrypting the login information so that only the node app you're using knows of the "key" to decrypt it and reuse the login details. Otherwise, if you have control over the login backend, you can try to return a temporary login "token" that expires after a day(s), save that token locally (encrypted/or not, your choice), and allow your backend system to use tokens to perform these *quick logins* under the hood. – chamberlainpi Apr 04 '19 at 13:11

1 Answers1

3

Vorpal.js was made to solve this exact problem. It works and feels almost exactly like Commander, however once the command ends, you don't exit the app - it drops you into an interactive CLI environment that you create. It uses Inquirer for its prompts.

Disclaimer: I wrote Vorpal.js

dthree
  • 19,847
  • 14
  • 77
  • 106