File tree Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Expand file tree Collapse file tree 1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -766,16 +766,16 @@ type contextKey struct {
766
766
func Middleware () func (http .Handler ) http .Handler {
767
767
return func (next http .Handler ) http .Handler {
768
768
return http .HandlerFunc (func (w http .ResponseWriter , r * http .Request ) {
769
- c, err := r .Cookie ( " token " )
769
+ header := r .Header . Get ( " Authorization " )
770
770
771
771
// Allow unauthenticated users in
772
- if err != nil || c == nil {
772
+ if header == " " {
773
773
next .ServeHTTP (w, r)
774
774
return
775
775
}
776
776
777
777
// validate jwt token
778
- tokenStr := c . Value
778
+ tokenStr := header
779
779
username, err := jwt .ParseToken (tokenStr)
780
780
if err != nil {
781
781
http .Error (w, " Invalid token" , http .StatusForbidden )
@@ -790,9 +790,8 @@ func Middleware() func(http.Handler) http.Handler {
790
790
return
791
791
}
792
792
user .ID = strconv .Itoa (id)
793
-
794
793
// put it in context
795
- ctx := context .WithValue (r .Context (), userCtxKey, user)
794
+ ctx := context .WithValue (r .Context (), userCtxKey, & user)
796
795
797
796
// and call the next with our new context
798
797
r = r .WithContext (ctx)
You can’t perform that action at this time.
0 commit comments