In ClojureScript, I initially stored login credentials and authorization information in an atom state. However, I encountered a persistent issue where the atom state gets flushed upon page refresh, leading me to explore alternative storage solutions.
Previous Approach:
(set! (.-cookie js/document) {:customer true :supplier false :admin false :user "test" :company "company-test"})
Questions:
I'm seeking recommendations for a more reliable way to store login credentials persistently on the client side without losing data upon page refresh.
Is storing sensitive data such as login credentials in cookies a secure approach? Are there potential vulnerabilities or better alternatives that offer enhanced security?
The best practice to store credentials (login+password+whatever else) on the frontend side is not to store them. You store a secure cookie with the right session ID, not the credentials themselves. If the cookie is not a session one, it's a permanent one. Such a cookie also has an expiration date. Of course, that requires you to have a backend that can store all the session information.
I wouldn't call the map in your code block "credentials", it's more like "user properties" or something like that. They shouldn't be persisted anywhere except for the server, and on every page load those details should be retrieved again using the session ID stored in the cookie. Note that you don't need to do anything on the client side to make cookies work - it's all done on the backend.