Hello,
I’m trying to enable basic authentication for certain URLs, but unfortunately, from another route if I use FlowRouter.go
then somehow it opens the corresponding URL without basic authentication…
Here’s what I do to enable basic auth;
// inside of HttpBasicAuth
var basicAuth = WebAppInternals.NpmModules.connect.module.basicAuth;
routes = routes || [''];
for(var i=0; i<routes.length; i++) {
WebApp.connectHandlers.stack.splice(i, 0, {
route: routes[i],
handle: basicAuth(this.callback, this.realm)
});
}
}
};
// Usage
const auth = new HttpBasicAuth(((username, password) => (process.env.MONGOCLIENT_USERNAME === username && process.env.MONGOCLIENT_PASSWORD === password)));
auth.protect(
[
'/',
'/databaseStats'
]
);
Using the latest version of both FlowRouter
and Meteor