Add frontend support for custom flashed data keys
This commit is contained in:
parent
ca39c3e538
commit
e72bb08a66
@ -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>",
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user