jaredhanson/connect-flash

add getFlash and setFlash methods

Closed this issue · 2 comments

Right now, the only way to get AND set the flash parameters is through req.flash().

However, this can lead to unexpected situations, imagine a case where you call req.flash('msg', obj.with.string); but somehow, obj.with.string equals null, zero or empty string.

This will flush the complete msg buffer and you'll wonder where your flash message went. I therefore suggest to seperate the logic of adding flashMessages and getting/cleaning them!

This module is attempting to be compatible with the API exposed by Express 2.x. Additionally, I think it is preferable to keep extensions to req at a minimum. If you need to flash potentially undefined strings, check before invoking req.flash.

if (obj.with.string) { req.flash('msg', obj.with.string); }

@jaredhanson Why not change https://github.com/jaredhanson/connect-flash/blob/master/lib/flash.js#L62 to:

if (type && typeof msg !== 'undefined') {

This way, the only time when you need to check the second argument is when you have a potentially undefined value.