Hi,
I’m trying to build an app.
This app should force the user to create a password for ‘admin’ user in its first run
I’m trying to implement this in onBeforeAction, but It gets executed twice.
var isFirstRun = function() {
var admin = Meteor.users.findOne({ username: 'admin' }).username;
if (admin) {
console.log('Admin exists');
this.next();
} else {
console.log('This is a first run');
this.render('firstRun')
}
}
Router.onBeforeAction(isFirstRun);
// Browser Console Output
Exception in callback of async function: TypeError: Cannot read property 'username' of undefined
at isFirstRun (http://localhost:3000/lib/router.js?917bd3d2a86483a854caf15cfd5a37d81198a239:23:57)
at http://localhost:3000/packages/iron_router.js?7b16fe70bccff9182aca02afb2ccd7708ac57c64:1209:36
at _.extend.withValue (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:955:17)
at Router.addHook.hookWithOptions (http://localhost:3000/packages/iron_router.js?7b16fe70bccff9182aca02afb2ccd7708ac57c64:1208:27)
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?56e0c02a758f48c0a704ca978a8fb6d7bd9ebbab:424:31)
at Meteor.bindEnvironment (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:22)
at onRerun (http://localhost:3000/packages/iron_router.js?7b16fe70bccff9182aca02afb2ccd7708ac57c64:521:9)
at boundNext (http://localhost:3000/packages/iron_middleware-stack.js?56e0c02a758f48c0a704ca978a8fb6d7bd9ebbab:424:31)
at Meteor.bindEnvironment (http://localhost:3000/packages/meteor.js?43b7958c1598803e94014f27f5f622b0bddc0aaf:983:22)
at onRun (http://localhost:3000/packages/iron_router.js?7b16fe70bccff9182aca02afb2ccd7708ac57c64:508:9)
Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?
Admin exists