website icon indicating copy to clipboard operation
website copied to clipboard

Flash, flash & flash, the system is broken and we need some alternative

Open fcaps opened this issue 2 years ago • 1 comments

Current status: most of the flash messages are not working.

including some weird configurations with:

        flash.type = 'Error!'
        flash.class = 'alert-danger'
        flash.messages = [{ msg: 'The invitation link is wrong or truncated. Key informations are missing.' }]

        const buff = Buffer.from(JSON.stringify(flash))
        const data = buff.toString('base64')

        return res.redirect('/clans?flash=' + data)

there is an old flash implementation https://github.com/jaredhanson/connect-flash, but this is 10 years old and actually not used in the code, we start it with:

#AppKernel
        this.expressApp.use(flash())
        this.expressApp.use((req, res, next) => {
            res.locals.message = req.flash()
            next()
        })

but never written or used in the templates....

To stop this madness, we need a proper session-flash implementation and stop using multiple systems or structures. No reddirest with "?flash=knhdsfapoinbgoiua", no custom made objects and template mixins.

Base Acceptance criteria:

  • if the user destroys a clan or makes any mutating action, a flash message should be saved in the session
  • on rendering a site, a flash-message should pop up

non-goals:

  • using flash messages to show validation errors

something like

fcaps avatar Dec 04 '23 17:12 fcaps

UPDATE:

for a pure flash implementation (a sinlge message) you can use:

 await req.asyncFlash('info', 'My Message')

this will be rendered in the default template on the next site:

#default.pug
 +flash-connect(connectFlash)

#mixin
mixin flash-connect(connectFlash)
    - var flashes = connectFlash()
        if flashes
            if flashes.info
                div.alert(class='alert-success')
                    ul
                    each info in flashes.info
                        li !{info}
            if flashes.error
                div.alert(class='alert-danger')
                    ul
                    each error in flashes.error
                        li !{error}

fcaps avatar Dec 05 '23 19:12 fcaps