Add frontend support for custom flashed data keys

This commit is contained in:
Alice Gaudon 2020-07-06 10:42:46 +02:00
parent ca39c3e538
commit e72bb08a66
2 changed files with 11 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wms-core",
"version": "0.10.18",
"version": "0.10.19",
"description": "Node web framework",
"repository": "git@gitlab.com:ArisuOngaku/wms-core.git",
"author": "Alice Gaudon <alice@gaudon.pro>",

View File

@ -36,17 +36,22 @@ export default class SessionComponent extends ApplicationComponent<void> {
res.locals.session = req.session;
let _flash: any = null;
res.locals.flash = () => {
if (!_flash) {
_flash = {
let _flash: any = {};
res.locals.flash = (key?: string) => {
if (key !== undefined) {
if (_flash[key] === undefined) _flash[key] = req.flash(key) || null;
return _flash[key];
}
if (_flash._messages === undefined) {
_flash._messages = {
info: req.flash('info'),
success: req.flash('success'),
warning: req.flash('warning'),
error: req.flash('error'),
};
}
return _flash;
return _flash._messages;
};
next();
});