Golang-JWT-Gin-Authentication-project
Golang-JWT-Gin-Authentication-project copied to clipboard
{"error":"No Authorization header provided"} shown even for test endpoints
There seems to be an issue where with recent versions of Gin, all endpoints get protected, even the /api-1
and /api-2
endpoints.
When running the code in the repo with go run main.go
and testing with Postman:
GET /api-2 HTTP/1.1
User-Agent: PostmanRuntime/7.31.1
Accept: */*
Postman-Token: d0265184-15e4-46ec-aef6-e7fc553fdac8
Host: localhost:9000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Date: Sun, 26 Feb 2023 18:38:12 GMT
Content-Length: 44
{"error":"No Authorization header provided"}
What am i missing?
just Comment this line (incomingRoutes.Use(middleware.Authentication()) ) in userRouter file and remove the respective package, and then add the below lines in the same file incomingRoutes.POST("/users/signup",controller.SignUp()) incomingRoutes.POST("/users/login",controller.Login())
and add this router.Use(middleware.Authentication()) in main.go,did make all those changes please have in main repo
finally post, { "Email":"[email protected]", "First_name":"Admin", "Last_name":"Nowhere", "Password":"Pass@123", "User_type":"ADMIN", "Phone":"87867055852"
}