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

Fix setting session when middleware redirects instead of continuing request flow #581

Conversation

girardinsamuel
Copy link
Contributor

@girardinsamuel girardinsamuel commented Apr 12, 2022

An issue has been observed when using a middleware which set some data in session (flash data or not) as in the example below:

class SomeMiddleware(Middleware):

    def before(self, request, response):
        if condition:
             Session.set("key", "value")
             return response.redirect("/").with_errors("Some error")
        return request

Neither key nor errors are correctly set into session when the redirected route loads because it does not load the session correctly because no cookies had been added to the response for those keys.
It's because Session.save() in the upper SessionMiddleware.after() method had never been called because of the redirect.

So now, .save() is called at each session data update:

  • set
  • flash
  • delete
  • pull
  • get (only in case of flash data)

This PR fixes it.

@girardinsamuel girardinsamuel added the Next Patch Non breaking fixes that are not really new features that can go in next patch version label Apr 12, 2022
@josephmancuso josephmancuso merged commit 3309d38 into MasoniteFramework:4.0 Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Next Patch Non breaking fixes that are not really new features that can go in next patch version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants