Session flash in seperate function inside Method

Hello out there.
I want to send a message in session.flash(). But it doesn’t show the message in the edge.

I have a method with my code. And I need to send several messages for different cases. So I thought, I can write that in a seperate function, because I don’t have to copy that a hundred of times.

My code is:

this.writeToDatabase(timelog)

                .then(result => {

                    if(result === true) {

                       flashSession(`${request.body.stamp} erfolgreich gestartet!`)

                    }

            })

The function is:

function flashSession(infoMessage) {

        session.flash({ type:'info', message: infoMessage })

    }

The message is coming into the seperate function. But it will not be stored in the session.

Thanks to all

Hello @marselle!

Can you give more context? Where is this.writeToDatabase? and where is flashSession? Are they in providers or are they in controllers or models or some other place?

Where are you calling them and how does session get into flashSession?

Hello @McSneaky,

This code is all in a Controller. The function flashSession() is inside the Method where session is initialized as a Provider

async checkClickedButton({ request, session, response })

writeToDatabase is a seperate method in this controller which writes some data into a database. This is happening without any problem.

So I hope this helps you out to help me out :smiley:
Thank you