Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fcaps opened this issue Dec 4, 2023 · 1 comment
Open
Labels

Comments

@fcaps
Copy link
Collaborator

fcaps commented Dec 4, 2023

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 fcaps added the Bug label Dec 4, 2023
@fcaps
Copy link
Collaborator Author

fcaps commented Dec 5, 2023

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}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant