I have follow the documentation of auth0 to implement profile picture and other profile data. The profile object from auth0 is empty until the page is loaded. Here is my code to call profile data from navbar component,
ngOnInit() {
if (this.auth.userProfile) {
this.profile = this.auth.userProfile;
return;
}
if (this.auth.authenticated) {
this.auth.getProfile((err, profile) => {
this.profile = profile;
});
}
}
Here is getProfile method from auth.service,
public getProfile(cb): void {
const accessToken = localStorage.getItem('access_token');
if (!accessToken) {
throw new Error('Access token must exist to fetch profile');
}
const self = this;
this.auth0.client.userInfo(accessToken, (err, profile) => {
if (profile) {
self.userProfile = profile;
}
cb(err, profile);
});
}
After login, i get the error 'Access token must exist to fetch profile' but if i reload it i dont see it.