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

🐞 [Bug]: v3 Flash Message with redirect is not working #3038

Closed
3 tasks done
patelajay745 opened this issue Jun 19, 2024 · 3 comments · Fixed by #3046
Closed
3 tasks done

🐞 [Bug]: v3 Flash Message with redirect is not working #3038

patelajay745 opened this issue Jun 19, 2024 · 3 comments · Fixed by #3046

Comments

@patelajay745
Copy link

patelajay745 commented Jun 19, 2024

Question Description

I am sending flash message using below code

return c.Redirect().With("status","added").To("/dashboard")

and try to retrieve it using below code

message := c.Redirect().Message("status")

Not getting anything.

Is there anything wrong?

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
Copy link

welcome bot commented Jun 19, 2024

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87
Copy link
Member

thanks for the report we will have a look in the next hours/days

@ReneWerner87
Copy link
Member

thx for the report

example:

package main

import (
	"fmt"
	"log"

	"github.com/gofiber/fiber/v3"
)

func main() {
	app := fiber.New()

	app.Get("/redirectWithRoute", func(c fiber.Ctx) error {
		return c.Redirect().With("status", "Logged in successfully").Route("base")
	})
	app.Get("/redirectWithTo", func(c fiber.Ctx) error {
		return c.Redirect().With("status", "Logged in successfully").To("/")
	})

	app.Get("/", func(c fiber.Ctx) error {
		fmt.Println("messages", c.Redirect().Messages())
		// => Logged in successfully
		return c.SendString(c.Redirect().Message("status"))
	}).Name("base")

	log.Fatalln(app.Listen(":3000"))
}

curl
http://localhost:3000/redirectWithTo
http://localhost:3000/redirectWithRoute

currently there is only the flash messages functionality in the Route method

fiber/redirect.go

Lines 204 to 233 in ba6ea67

if len(r.messages) > 0 || len(r.oldInput) > 0 {
messageText := bytebufferpool.Get()
defer bytebufferpool.Put(messageText)
// flash messages
for i, message := range r.messages {
messageText.WriteString(message)
// when there are more messages or oldInput -> add a comma
if len(r.messages)-1 != i || (len(r.messages)-1 == i && len(r.oldInput) > 0) {
messageText.WriteString(CookieDataSeparator)
}
}
r.messages = r.messages[:0]
// old input data
i := 1
for k, v := range r.oldInput {
messageText.WriteString(OldInputDataPrefix + k + CookieDataAssigner + v)
if len(r.oldInput) != i {
messageText.WriteString(CookieDataSeparator)
}
i++
}
r.c.Cookie(&Cookie{
Name: FlashCookieName,
Value: r.c.app.getString(messageText.Bytes()),
SessionOnly: true,
})
}

but we will move this to the To function

because other methods(Route, Back) are using this internally
https://github.com/gofiber/fiber/blob/main/redirect.go#L250-L253
https://github.com/gofiber/fiber/blob/main/redirect.go#L270

@ReneWerner87 ReneWerner87 self-assigned this Jun 27, 2024
@ReneWerner87 ReneWerner87 changed the title 🤗 [Question]: v3 Flash Message with redirect is not working 🐞 [Bug]: v3 Flash Message with redirect is not working Jun 27, 2024
ReneWerner87 added a commit that referenced this issue Jun 27, 2024
🐞 [Bug]: v3 Flash Message with redirect is not working #3038
ReneWerner87 added a commit that referenced this issue Jun 27, 2024
🐞 [Bug]: v3 Flash Message with redirect is not working #3038
ReneWerner87 added a commit that referenced this issue Jun 28, 2024
* fixes #3038
🐞 [Bug]: v3 Flash Message with redirect is not working #3038

* fixes #3038
🐞 [Bug]: v3 Flash Message with redirect is not working #3038
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants