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 messages are not deleted after read #265

Open
vcraescu opened this issue Feb 4, 2020 · 5 comments
Open

Flash messages are not deleted after read #265

vcraescu opened this issue Feb 4, 2020 · 5 comments

Comments

@vcraescu
Copy link

@vcraescu vcraescu commented Feb 4, 2020

What version of aah are you using (aah --version)?

aah v0.12.2
cli v0.13.4
go v1.13.7

Does this issue reproduce with the latest release?

Yes.

What operating system are you using (such as macOS, Linux and Windows)?

macOS

What did you do?

In controller:

c.Session().SetFlash("error", "Some error message")

In view:

{{ flash . "error" }}

What did you expect to see?

I expect to get the flash message only once but when I refresh the page the flash message is still present in the session.

What did you see instead?

The flash message should be removed from the session if it is read once. It is removed from memory but it is not removed from file session.

@vcraescu vcraescu changed the title Flash message are not deleted Flash messages are not deleted after read Feb 4, 2020
@vcraescu

This comment has been minimized.

Copy link
Author

@vcraescu vcraescu commented Feb 4, 2020

ctx.writeCookies()

// Set Cookies
	ctx.writeCookies()

	if re.redirect { // handle redirects
		ctx.Log().Debugf("Redirecting to '%s' with status '%d'", re.path, re.Code)
		http.Redirect(ctx.Res, ctx.Req.Unwrap(), re.path, re.Code)
		return
	}

	// Check ContentType and detect it if need be
	if len(re.ContType) == 0 {
		if _, ok := re.Rdr.(*binaryRender); !ok {
			re.ContentType(ctx.detectContentType())
		}
	}
	if len(re.ContType) > 0 {
		ctx.Res.Header().Set(ahttp.HeaderContentType, re.ContType)
	}

	// 'OnHeaderReply' HTTP event
	e.publishOnHeaderReplyEvent(ctx.Res.Header())

	if bodyAllowedForStatus(re.Code) {
		if e.a.viewMgr != nil && re.isHTML() {
			e.a.viewMgr.resolve(ctx)
		}

		e.writeOnWire(ctx)

Apparently the session is saved before template is actually rendered. That's why the flash message is retained.

@vcraescu

This comment has been minimized.

Copy link
Author

@vcraescu vcraescu commented Feb 4, 2020

Managed to mitigate this issue using a PostReply subscriber:

	aah.App().HTTPEngine().OnPostReply(func(e *aah.Event) {
		ctx, ok := e.Data.(*aah.Context)
		if !ok {
			return
		}

		if err := aah.App().SessionManager().SaveSession(ctx.Res, ctx.Session()); err != nil {
			ctx.Log().Errorf("error saving session: %v", err)
			return
		}

		ctx.Log().Println("session successfully saved")
	})
@jeevatkm

This comment has been minimized.

Copy link
Member

@jeevatkm jeevatkm commented Feb 9, 2020

@vcraescu Thanks for reporting an issue. I will have a look and address the issue.

@vcraescu

This comment has been minimized.

Copy link
Author

@vcraescu vcraescu commented Feb 9, 2020

thanks!

@vcraescu

This comment has been minimized.

Copy link
Author

@vcraescu vcraescu commented Feb 16, 2020

@jeevatkm any news?

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.