Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use('/api/admin/', (req, res, next) => {
if (req.user) {
next();
} else {
// Instruct unleash-frontend to pop-up auth dialog
return res
.status('401')
.json(
new AuthenticationRequired({
path: '/unleash/api/admin/login',
type: 'custom',
message: `You have to identify yourself in order to use Unleash.
Click the button and follow the instructions.`,
})
)
.end();
}
});
}
app.use('/api/admin/', (req, res, next) => {
if (req.user) {
next();
} else {
// Instruct unleash-frontend to pop-up auth dialog
return res
.status('401')
.json(
new AuthenticationRequired({
path: '/api/admin/login',
type: 'custom',
message: `You have to identify yourself in order to use Unleash.
Click the button and follow the instructions.`,
})
)
.end();
}
});
}
app.use('/api/admin/', (req, res, next) => {
const email = req.get('X-Auth-Email');
if (email) {
// TODO: need to do some verification of credentials here, probably
// validate X-Auth-Token signature
const user = new unleash.User({ email: `${email}` });
req.user = user;
next();
} else {
return res
.status('401')
.end('access denied');
}
});
});
};
options.preRouterHook = gatekeeperAuthentication;
function serveFrontend(app) {
app.use('/', express.static('/frontend'));
}
options.preHook = serveFrontend;
if (process.env.DATABASE_URL_FILE) {
options.databaseUrl = fs.readFileSync(process.env.DATABASE_URL_FILE);
}
unleash
.start(options)
.then(server => {
console.log(
`Unleash API started on http://localhost:${server.app.get('port')}`
);
});
(accessToken, refreshToken, profile, done) => {
done(
null,
new User({
name: profile.displayName,
email: profile.emails[0].value,
})
);
}
)