'How to save token in frontend with security
I have a token-based authentication. In the frontend, how can I handle token security? I heard localstroage and cookie(without httppnly) are not safe. so how can I save that token to localstroage? by encrypting? is frontend encryption safe?
Solution 1:[1]
(Typing from phone, can add details later)
For starters you are not using the interface. You defined a class and an interface that are completely unrelated and only have similar names.
To actually use the interface you’d have to do something like:
class UserAccount implements User { … }
Now answering your questions:
There many reasons one would create interfaces. For instance you could share the interface with a different parte of the code letting it know what a UserAccount looks like without creating a dependency on the class itself. Another user can be to define multiple interfaces such as “SoundPlayer” and “GraphicsPlayer”, then have a class implement one or both. Those classes could represent a music player by implementing “SoundPlayer” or a multimedia player by implementing both. This also ensures that classes with similar functions “look the same”.
Not sure what you’re asking but I feel like you were expecting some sort of error that won’t occur since you’re not actually implementing the interface.
You can’t access user.username because it is part of the class UserAccount and not part of the interface.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Guilherme Brunow |
