Stop Using LocalStorage For Token ❌
hello everyone today we will talk about where should we store the token.
LocalStorage ❌
Well, we use local storage for many things but we should not use token storage. For example, ı want to set our token for cross-domain such as google, such as sso. We can’t do this as local storage is a single-domain storage
if I want to set token cross-domain ı must use cookies.
Cookie ✅
Now we will set cookies for the same domains.
<script type="text/javascript">
var cookieName = 'HelloWorld';
var cookieValue = 'HelloWorld';
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate
+ ";domain=.example.com;path=/";
</script>
That’s it, if I go to my domain I will see the token set. Such as google look like this
two different application one is Gmail other one is google slides but they are using the same token for authentication.
Good work everyone.