I\'d like to pass the user, found during the AuthorizeStep
to either the App class
and then to the home module
.
Here\'s what
In my app I created a class called AuthContext with currentUser property. You can inject it in the constructor for the AuthorizeStep and then inject it in any other models that need it. Something like...
import {AuthContext} from './auth-context';
export class App {
static inject() { return [AuthContext];}
constructor(authcontext){
this.authContext = authcontext;
}
configureRouter(config, router) {
config.addPipelineStep('authorize', AuthorizeStep);
config.map([
{route: ['', ':filter'], name: "", moduleId: 'welcome'}
{route: 'home', name: "home", moduleId: 'home' auth:true}
]);
this.router = router;
}
}
class AuthorizeStep {
static inject() { return [AuthContext];}
constructor(authcontext){
this.authContext = authcontext;
}
run(routingContext, next) {
if (routingContext.nextInstructions.some(i => i.config.auth)) {
this.client.get('auth/login')
.then(response => {
this.authcontext.user = response.content;
});
}
return next();
}
}