Skip to content

Commit

Permalink
upadted session re-add for uniformity accross modules
Browse files Browse the repository at this point in the history
Other modules will probably not expect a MessageBag as the content of the session ‘errors’ key.
So just pass it through
  • Loading branch information
circulon committed Aug 22, 2024
1 parent 51ceb16 commit 4703868
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/masonite/middleware/route/SessionMiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ def before(self, request, response):
request.app.make("response").with_success = self.with_success
request.app.make("request").session = Session

# TODO: Remove in Masonite 5
errors = Session.get("errors") or {}
request.app.make("view").share({"errors": MessageBag(errors).helper})
# errors are stored in session flash so 'getting' them actually clears them
# if any then re-add them to the session
# TODO: Check this in Masonite 5
# errors are stored in session flash so 'getting' them
# actually clears them out of the session
errors = Session.get("errors")
request.app.make("view").share({"errors": MessageBag(errors or {}).helper})
# if any errors then re-add them to the session
if errors:
Session.flash('errors', errors)
Session.flash("errors", errors)

return request

def after(self, request, _):
Expand Down

0 comments on commit 4703868

Please sign in to comment.