2

I want to let the user login and a few actions will give them a string, this string needs to be stored somewhere so that even after they logout and login later on, the string can get auto-filled in a text box.

  • Frontend: React
  • Backend: Node, mysql

Would cookies be feasible? If so kindly guide me as to how.

James Z
  • 12,209
  • 10
  • 24
  • 44
SuperDope
  • 25
  • 4
  • `let the user login and a few actions will give them a String` - What does it mean? What is string here the login cred or the input form text? – Apoorva Chikara May 12 '22 at 03:58

1 Answers1

1

You can do it with JavaScript using localStorage.

For example:

localStorage.setItem('myLoginString', their_loginString);

You can then fetch the value later with:

their_loginString = localStorage.getItem('myLoginString');

This is stored in their browser, so:

  1. The string would need to be generated on the browser side, or fetched from the server with an AJAX request or similar.

  2. It is unique to that browser. If they load a different one, then the saved string won't be there.

Jacob Ewing
  • 770
  • 7
  • 22
  • 1
    You could also do the same thing using cookies to identify the browser and providing the string from the server. – Jacob Ewing May 12 '22 at 03:35