Skip to content

Commit 8bceeed

Browse files
committed
fix: fiber example
1 parent e4dd6a7 commit 8bceeed

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [unreleased]
9+
- Fixes go fiber to handle handler chaining correctly with verifySession.
910

1011
## [0.9.7] - 2022-10-20
1112
- Updated Frontend integration test server for angular tests

examples/with-fiber/main.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword"
1717
"github.com/supertokens/supertokens-golang/recipe/thirdpartyemailpassword/tpepmodels"
1818
"github.com/supertokens/supertokens-golang/supertokens"
19-
"github.com/valyala/fasthttp"
2019
)
2120

2221
func main() {
@@ -121,25 +120,13 @@ func main() {
121120
// wrapper of the original implementation of verify session to match the required function signature
122121
func verifySession(options *sessmodels.VerifySessionOptions) fiber.Handler {
123122
return func(c *fiber.Ctx) error {
124-
return adaptor.HTTPHandlerFunc(http.HandlerFunc(session.VerifySession(options, func(rw http.ResponseWriter, r *http.Request) {
123+
err := adaptor.HTTPHandlerFunc(session.VerifySession(options, func(rw http.ResponseWriter, r *http.Request) {
125124
c.SetUserContext(r.Context())
126-
err := c.Next()
127-
if err != nil {
128-
err = supertokens.ErrorHandler(err, r, rw)
129-
if err != nil {
130-
rw.WriteHeader(500)
131-
_, _ = rw.Write([]byte(err.Error()))
132-
}
133-
return
134-
}
135-
c.Response().Header.VisitAll(func(k, v []byte) {
136-
if string(k) == fasthttp.HeaderContentType {
137-
rw.Header().Set(string(k), string(v))
138-
}
139-
})
140-
rw.WriteHeader(c.Response().StatusCode())
141-
_, _ = rw.Write(c.Response().Body())
142-
})))(c)
125+
}))(c)
126+
if err != nil {
127+
return err
128+
}
129+
return c.Next()
143130
}
144131
}
145132

0 commit comments

Comments
 (0)