Closed isrealbm closed 1 year ago
When I try to use jwt.Validate in my application, it's always be error.
jwt.Validate
http: panic serving [::1]:60976: runtime error: invalid memory address or nil pointer dereference goroutine 45 [running]:
I tried to use an other custom middleware but still got an error from this function, please help!
"GET http://localhost:****/track HTTP/1.1" from [::1]:64115 - 000 0B in 297.334µs 2023/06/28 23:54:48 http: panic serving [::1]:64115: runtime error: invalid memory address or nil pointer dereference goroutine 36 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1850 +0xbf panic({0x1372980, 0x1675fd0}) /usr/local/go/src/runtime/panic.go:890 +0x262 github.com/go-chi/jwtauth/v5.(*JWTAuth).parse(0x0, {0xc00024a0b0, 0xac, 0xb0}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:140 +0xb6 github.com/go-chi/jwtauth/v5.(*JWTAuth).Decode(...) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:131 github.com/go-chi/jwtauth/v5.VerifyToken(0xc000099838?, {0xc0002340c5?, 0x10?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:100 +0x3c github.com/go-chi/jwtauth/v5.VerifyRequest(0x0?, 0x0?, {0xc0001192d0, 0x2, 0x0?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:95 +0xac github.com/go-chi/jwtauth/v5.Verify.func1.1({0x29d75128, 0xc00021e300}, 0xc000224500) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:71 +0x89 net/http.HandlerFunc.ServeHTTP(0xc0001d2000?, {0x29d75128?, 0xc00021e300?}, 0xc00023c240?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*ChainHandler).ServeHTTP(0x13707e0?, {0x29d75128?, 0xc00021e300?}, 0xc000226034?) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/chain.go:31 +0x2c github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc00012a300, {0x29d75128, 0xc00021e300}, 0xc000224500) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:444 +0x216 net/http.HandlerFunc.ServeHTTP(0xc000224400?, {0x29d75128?, 0xc00021e300?}, 0xd0?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5/middleware.RequestLogger.func1.1({0x14814d0, 0xc00022a2a0}, 0xc000224400) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/middleware/logger.go:54 +0x17d net/http.HandlerFunc.ServeHTTP(0x1481998?, {0x14814d0?, 0xc00022a2a0?}, 0x1675e00?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc00012a300, {0x14814d0, 0xc00022a2a0}, 0xc000224300) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:90 +0x310 net/http.serverHandler.ServeHTTP({0xc0002142a0?}, {0x14814d0, 0xc00022a2a0}, 0xc000224300) /usr/local/go/src/net/http/server.go:2947 +0x30c net/http.(*conn).serve(0xc0002180a0, {0x1481a40, 0xc0001d2720}) /usr/local/go/src/net/http/server.go:1991 +0x607 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3102 +0x4db 2023/06/28 23:54:48 "GET http://localhost:****/track HTTP/1.1" from [::1]:64120 - 000 0B in 152.666µs 2023/06/28 23:54:48 http: panic serving [::1]:64120: runtime error: invalid memory address or nil pointer dereference goroutine 25 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1850 +0xbf panic({0x1372980, 0x1675fd0}) /usr/local/go/src/runtime/panic.go:890 +0x262 github.com/go-chi/jwtauth/v5.(*JWTAuth).parse(0x0, {0xc000154210, 0xac, 0xb0}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:140 +0xb6 github.com/go-chi/jwtauth/v5.(*JWTAuth).Decode(...) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:131 github.com/go-chi/jwtauth/v5.VerifyToken(0xc000068838?, {0xc0001dc0c5?, 0x10?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:100 +0x3c github.com/go-chi/jwtauth/v5.VerifyRequest(0x0?, 0x0?, {0xc0001192d0, 0x2, 0x0?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:95 +0xac github.com/go-chi/jwtauth/v5.Verify.func1.1({0x29d75128, 0xc0001d64c0}, 0xc00019e700) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:71 +0x89 net/http.HandlerFunc.ServeHTTP(0xc0001d2000?, {0x29d75128?, 0xc0001d64c0?}, 0xc0001254f0?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*ChainHandler).ServeHTTP(0x13707e0?, {0x29d75128?, 0xc0001d64c0?}, 0xc000132274?) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/chain.go:31 +0x2c github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc00012a300, {0x29d75128, 0xc0001d64c0}, 0xc00019e700) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:444 +0x216 net/http.HandlerFunc.ServeHTTP(0xc00019e600?, {0x29d75128?, 0xc0001d64c0?}, 0xd0?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5/middleware.RequestLogger.func1.1({0x14814d0, 0xc000192380}, 0xc00019e600) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/middleware/logger.go:54 +0x17d net/http.HandlerFunc.ServeHTTP(0x1481998?, {0x14814d0?, 0xc000192380?}, 0x1675e00?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc00012a300, {0x14814d0, 0xc000192380}, 0xc00019e500) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:90 +0x310 net/http.serverHandler.ServeHTTP({0xc0001d2a80?}, {0x14814d0, 0xc000192380}, 0xc00019e500) /usr/local/go/src/net/http/server.go:2947 +0x30c net/http.(*conn).serve(0xc0001b1220, {0x1481a40, 0xc0001d2720}) /usr/local/go/src/net/http/server.go:1991 +0x607 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3102 +0x4db 2023/06/28 23:54:48 "GET http://localhost:****/track HTTP/1.1" from [::1]:64121 - 000 0B in 1.013041ms 2023/06/28 23:54:48 http: panic serving [::1]:64121: runtime error: invalid memory address or nil pointer dereference goroutine 6 [running]: net/http.(*conn).serve.func1() /usr/local/go/src/net/http/server.go:1850 +0xbf panic({0x1372980, 0x1675fd0}) /usr/local/go/src/runtime/panic.go:890 +0x262 github.com/go-chi/jwtauth/v5.(*JWTAuth).parse(0x0, {0xc000298160, 0xac, 0xb0}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:140 +0xb6 github.com/go-chi/jwtauth/v5.(*JWTAuth).Decode(...) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:131 github.com/go-chi/jwtauth/v5.VerifyToken(0xc00006e838?, {0xc00028e0c5?, 0x10?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:100 +0x3c github.com/go-chi/jwtauth/v5.VerifyRequest(0x0?, 0x0?, {0xc0001192d0, 0x2, 0x0?}) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:95 +0xac github.com/go-chi/jwtauth/v5.Verify.func1.1({0x29d75128, 0xc00007c3c0}, 0xc000284500) ~/go/pkg/mod/github.com/go-chi/jwtauth/v5@v5.1.0/jwtauth.go:71 +0x89 net/http.HandlerFunc.ServeHTTP(0xc0001d2000?, {0x29d75128?, 0xc00007c3c0?}, 0xc000294240?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*ChainHandler).ServeHTTP(0x13707e0?, {0x29d75128?, 0xc00007c3c0?}, 0xc00002a10c?) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/chain.go:31 +0x2c github.com/go-chi/chi/v5.(*Mux).routeHTTP(0xc00012a300, {0x29d75128, 0xc00007c3c0}, 0xc000284500) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:444 +0x216 net/http.HandlerFunc.ServeHTTP(0xc000284400?, {0x29d75128?, 0xc00007c3c0?}, 0xd0?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5/middleware.RequestLogger.func1.1({0x14814d0, 0xc0002882a0}, 0xc000284400) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/middleware/logger.go:54 +0x17d net/http.HandlerFunc.ServeHTTP(0x1481998?, {0x14814d0?, 0xc0002882a0?}, 0x1675e00?) /usr/local/go/src/net/http/server.go:2109 +0x2f github.com/go-chi/chi/v5.(*Mux).ServeHTTP(0xc00012a300, {0x14814d0, 0xc0002882a0}, 0xc000284300) ~/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.8/mux.go:90 +0x310 net/http.serverHandler.ServeHTTP({0xc00007e240?}, {0x14814d0, 0xc0002882a0}, 0xc000284300) /usr/local/go/src/net/http/server.go:2947 +0x30c net/http.(*conn).serve(0xc0000000a0, {0x1481a40, 0xc0001d2720}) /usr/local/go/src/net/http/server.go:1991 +0x607 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:3102 +0x4db
I found the problem. I missed the tokenAuth value.
tokenAuth
glad to hear you figured it out :)
When I try to use
jwt.Validate
in my application, it's always be error.I tried to use an other custom middleware but still got an error from this function, please help!