Take for example something like this
const main_routes: Routes = [
{
path: "",
loadChildren: () => import("../auth.module").then(m => m.AuthModule),
resolve: {
user: GetUserResolver /*Calls loadCurrentUser() on a userService that can be used globally*/
}
},
{
path: "showvideo",
loadChildren: () => import("../show-video/show-video.module").then(m => m.ShowVideoModule)
},
{
path: "login",
loadChildren: () => LoginModule
},
{
path: "**",
component: NotFoundComponent
}
];
Authmodule is what users see when they're logged in. Inside of it there is this
const auth_routes: Routes = [
{
path: "",
component: AuthComponent,
canActivate: [ AuthGuard ],
children: [
/* Multiple of these */
{
path: "module",
loadChildren: () => Module
},
]
}
];
And inside some of the modules there's guards for specific user permissions.
This, I would assume would be fine enough to handle both getting user data on login, and on refresh. But this isn't the case as guards run before resolvers and the user permission guards throws ReferenceErrors because their userService doesn't contain a user, because the resolver that is supposed to get that user and put it into userService hasn't run yet.
So how is something like this supposed to be handled? The guards are supposed to check data in a user object, that object is supposed to be fetched on login and on reload of the page.