An Angular application allows users to login with their email and password. I want the current user's information to be displayed in app.component.html using localStorage when they are logged in. All user data is retrieved from a MySQL database.
Here is the code:
auth.service.ts:
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor() { }
getUserDetails() {
if(localStorage.getItem('userData')){
return localStorage.getItem('userData')
} else{
return null
}
}
setDataInLocalStorage(variableName, data) {
localStorage.setItem(variableName, data);
}
getToken() {
return localStorage.getItem('token');
}
clearStorage() {
localStorage.clear();
}
}