How to set in Angular cookies, type number values?
Why is Token Based Authentication more preferable Then Cookie based?
The cookie-based authentication has been the default and the cookie-based authentication is stateful.
What is Stateful?
Keep and track the previously stored information which is used for a current transaction.
A stateful service based on HTTP cookies uses the HTTP transport protocol and its ability to convey cookies, used as session context.
What are the Cookies Limitations?
We can only store around 20 cookies per web server and not more than 4KB of information in each cookie and they can last indefinitely should you choose to specify the max-age attribute.
Token Based Authentication -
The Token-based authentication has received expansion over last few years due to RESTful Web APIs, SPA and so on.
The Token based authentication is stateless.
What is Stateless?
Every transaction is performed as if it was being done for the very first time and there is no previously stored information used for the current transaction.
Token Based Authentication steps -
A user enters their login credentials and the server verifies the entered credentials. Validating to the entered credentials, It’s correct or not. If the credentials are correct, returns a signed token.
This token is stored in local storage on the client side. We can also store in session storage or cookie.
Advantages of Token-Based Authentication -
4. JWT is placed in the browsers local storage
5. Protect Cross Domain and CORS
6. Store Data in the JWT
7. Protect XSS and XSRF Protection
Where to Store Tokens?
It does depend on you, where you want to store the JWT. The JWT is placed in your browsers local storage.
For more detail kindly refer this link. https://www.code-sample.com/2018/05/angular-5-6-7-cookies-examples.html