I am trying to write an Aurelia-Starter for some “serverless infrastructure” start-up.
I followed the current docs for writing an AuthorizeStep, but the redirect doesn’t work.
Step
export class AuthorizeStep {
run(navigationInstruction, next) {
if (navigationInstruction.getAllInstructions().some(i => i.config.settings.auth)) {
db.ready().then(() => {
if (!db.User.me) {
devLog.debug('user not logged in');
return next.cancel(
new Redirect('login')
);
}
});
}
return next();
}
}
Routes
config.map([
{
route: ['', 'home'],
name: 'home',
moduleId: PLATFORM.moduleName('home'),
title: 'home',
nav: true,
settings: {auth: true} },
{
route: ['login'],
name: 'login',
moduleId: PLATFORM.moduleName('login'),
title: 'login',
// dont include this in the navigation model (router.navigation)
nav: false
}
]);
@bigopon
I enjoyed trying to put the problem in your sandbox!
It also kind of solved the problem, since when i stripped away the imported database stuff, the redirect worked.
True…
What confuses me tough is, that with the code above the logging worked, but the redirect didn´t - until i lifted everything out of the the anonymous function passed to db.ready().then()
I forgot about answering your question, please excuse me. What I was trying to say, was that
run(navigationInstruction, next) {
if (navigationInstruction.getAllInstructions().some(i => i.config.settings.auth)) {
db.ready().then(() => {
if (!db.User.me) {
devLog.debug('user not logged in');
return next.cancel(
new RedirectToRoute('login')
);
}
});
}
return next();
}
did not work, but
if (navigationInstruction.getAllInstructions().some(i => i.config.settings.auth)) {
if (!db.User.me) {
devLog.debug('user not logged in');
return next.cancel(
new RedirectToRoute('login')
);
}
}