I am trying to use a tutorial to make my first authentication setup with firebase in angular.
I do not understand the practice of instantly getting the user-item from the local storage after stringifying it.
/* Saving user data in localstorage when
logged in and setting up null when logged out */
this.afAuth.authState.subscribe((user) => {
if (user) {
this.userData = user;
localStorage.setItem('user', JSON.stringify(this.userData));
JSON.parse(localStorage.getItem('user')!);
} else {
localStorage.setItem('user', 'null');
JSON.parse(localStorage.getItem('user')!);
}
});
}
What could be the purpose if the JSON is not being stored in a variable?
https://www.positronx.io/full-angular-firebase-authentication-system/
I could not contact the author so I have to ask here.