Save Token to Local Storage

Handle log in and out by saving token to [Local Storage]

const handleLogin = async (event) => {
event.preventDefault()
try {
const user = await loginService.login({
username, password
})
window.localStorage.setItem(
'loggedBlogListAppUser', JSON.stringify(user)
)
setUser(user)
setUsername('')
setPassword('')
} catch (exception) {
setErrorMessage('Wrong credentials')
setTimeout(() => {
setErrorMessage(null)
}, 5000)
}
}
const handleLogout = () => {
window.localStorage.removeItem('loggedBlogListAppUser')
setUser(null)
}