File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 11package middleware
22
33import (
4+ "context"
45 "net/http"
56 "time"
67
7- "github.com/PythonHacker24/linux-acl-management-backend/internal/auth "
8+ "github.com/PythonHacker24/linux-acl-management-backend/internal/token "
89 "go.uber.org/zap"
910)
1011
@@ -34,9 +35,8 @@ func LoggingMiddleware(next http.HandlerFunc) http.HandlerFunc {
3435/* authentication middleware for http requests */
3536func AuthenticationMiddleware (next http.HandlerFunc ) http.HandlerFunc {
3637 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
37-
3838 /* authenticate the request through JWT */
39- username , err := auth .ExtractUsernameFromRequest (r )
39+ username , err := token .ExtractUsernameFromRequest (r )
4040 if err != nil {
4141 zap .L ().Error ("Error during authentication" ,
4242 zap .Error (err ),
@@ -47,7 +47,10 @@ func AuthenticationMiddleware(next http.HandlerFunc) http.HandlerFunc {
4747 /* set the header with the username */
4848 r .Header .Set ("X-User" , username )
4949
50+ /* pass username as context */
51+ ctx := context .WithValue (r .Context (), "username" , username )
52+
5053 /* return the handler */
51- next (w , r )
54+ next (w , r . WithContext ( ctx ) )
5255 })
5356}
You can’t perform that action at this time.
0 commit comments