1
votes

I'm using gin framework and I'm redirecting signin to home page when the user is already signed in. It shows this html element on the home page.

<a href="/signin">Found</a> "."

How to disable that element from the app?

This is my app code.

func GetSignIn(c *gin.Context) {
    // Get session from cookie. Check if email exists
    // redirect to Home page else show signin page.
    session := sessions.Default(c)
    if session.Get("email") != nil {
        fmt.Println(session.Get("email"))
        c.Redirect(302, "/")
    }
    c.HTML(200, "signin.html", "")
}

It seems like, it's a Go thing https://github.com/golang/go/blob/master/src/net/http/server.go#L2014

But I'm not sure, how to disable it. Would be great if someone guide me.

Thanks!

1

1 Answers

1
votes

Yeah, looks like it's a Go thing and you can't disable it. I suggest you to write your own Redirect structure like render.Redirect from Gin (you can embed it in your new structure to avoid some copy pasting):

https://github.com/gin-gonic/gin/blob/master/render/redirect.go

Write your own Render method for new structure based on code from net/http and then use redirect like this:

https://github.com/gin-gonic/gin/blob/32cab500ecc71d2975f5699c8a65c6debb29cfbe/context.go#L476

I think it's the simplest way to bypass such net/http redirect behavior.