I have a straightforward function that is designed to log in a user via local storage. I also have a second function that checks if the user can be found (I need them separated because I require the login check elsewhere).
logInUser(user: IPerson): Boolean {
localStorage.setItem(this.userID, JSON.stringify(user));
return this.isUserLoggedIn();
}
isUserLoggedIn(): Boolean {
return Boolean(localStorage.getItem(this.userID));
}
However, I feel like there may be issues with this code because I am not actually confirming that logInUser successfully completed its task; instead, I am just calling another function for verification. I have considered converting this into a Promise of boolean and chaining .then() but unfortunately, this approach does not work with setItem().
In theory, when setting something to local storage it does not return anything, so I am unsure how to properly verify that it was successful and handle any potential errors.