# No content on admin page reload

**URL:** <https://community.auth0.com/t/no-content-on-admin-page-reload/46896>\
**Category:** Get Help\
**Tags:** angular, auth0\
**Created:** [July 25, 2020, 10:47am UTC](https://community.auth0.com/t/no-content-on-admin-page-reload/46896 "2020-07-25T10:47:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown-enot](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/unknown-enot/32/22762_2.png) [@unknown-enot](https://community.auth0.com/u/unknown-enot)\
**Post date:** [July 25, 2020, 10:47am UTC](https://community.auth0.com/t/no-content-on-admin-page-reload/46896/1 "2020-07-25T10:47:14Z")

</div>

Hi,

I’m currently using NetCore 3.1 and Angular to create a single-page web app with authorization and authentication using new Auth0-spa-js. I have successfully implemented steps from Quickstart guide [Auth0-spa-js], assigned roles via dashboard and added them to token via rule function.

However, there is a problem with retrieving the roles in my angular app.  
I have a simple admin page(Admin text in h1 tags) the route of which is protected by CanActivate with standard AuthGuard and my AdminAuthGuard. When I am not signed in and try to manually go “/admin” - I am redirected to Auth0 login page and upon successful login, I am redirected back to “../admin”, which great. However, whenever I click “refresh page” all of the page content is gone (it’s just a blank white page) except for nav bar and my route becomes just “[https://localhost:5001](https://localhost:5001)”(no errors, no warnings appear). Afterwards, I still can manually click navbar buttons to back to the page that I was on. This whitelisting does not happen when I am on “/profile” page though that in protected only with AuthGuard.

So, I suppose the problem with retrieving roles from userProfile$.  
My AdminAuthGuard looks as follows:  
@Injectable()  
export class RoleGuard implements CanActivate, OnDestroy {  
subscription: Subscription;  
constructor(  
public auth: AuthService,  
public router: Router) {}  
canActivate(  
route: ActivatedRouteSnapshot,  
state: RouterStateSnapshot):  
Observable | Promise\<boolean|UrlTree\> | boolean {  
if(!this.auth.loggedIn) {  
return false;  
}  
//… your role guard check code goes here  
const expectedRole = route.data.expectedRole;  
var profile;  
this.subscription = this.auth.userProfile$.pipe(take(1)).subscribe(res =\> profile = res);  
if (profile)  
{  
if(profile[‘[https://dev-eu-vega.com/roles](https://dev-eu-vega.com/roles)’].indexOf(expectedRole) \> -1){  
console.log(‘Success’, profile);  
return true;  
}  
}  
this.router.navigate([‘/notauthorized’]);  
return false;  
};  
ngOnDestroy(){  
[//this.subscription.unsubscribe](https://this.subscription.unsubscribe)();  
}  
}

route from app.module.ts:  
{ path: ‘admin’, component: AdminComponent,  
canActivate: [AuthGuard, RoleGuard],  
data: {  
expectedRole: ‘Admin’  
}},

I would appreciate any help. Thanks in advance for your time and consideration.

---

<div class="post-metadata">

**Author:** ![unknown-enot](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/unknown-enot/32/22762_2.png) [@unknown-enot](https://community.auth0.com/u/unknown-enot)\
**Post date:** [July 28, 2020, 1:15pm UTC](https://community.auth0.com/t/no-content-on-admin-page-reload/46896/2 "2020-07-28T13:15:18Z")

</div>

Problem solved:  
canActivate(  
next: ActivatedRouteSnapshot,  
state: RouterStateSnapshot  
): Observable | Promise\<boolean|UrlTree\> | boolean {  
const expectedRole = next.data.expectedRole;  
return this.auth.userProfile$.pipe(  
switchMap(userProfile =\> userProfile[‘[https://dev-eu-vega.com/roles](https://dev-eu-vega.com/roles)’]),  
map((isInRole : string) =\> isInRole.indexOf(expectedRole) \> -1)  
);  
}

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 28, 2020, 1:52pm UTC](https://community.auth0.com/t/no-content-on-admin-page-reload/46896/3 "2020-07-28T13:52:29Z")

</div>

Thanks for sharing that with the rest of community! Glad you have figured it out!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [August 12, 2020, 1:52pm UTC](https://community.auth0.com/t/no-content-on-admin-page-reload/46896/4 "2020-08-12T13:52:33Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
