refactor: add auth token to the request context
This commit is contained in:
parent
040c662826
commit
93105fe5af
|
@ -16,6 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const DEFAULT_AUTH_CONTEXT_KEY = "user_id"
|
const DEFAULT_AUTH_CONTEXT_KEY = "user_id"
|
||||||
|
const AUTH_TOKEN_CONTEXT_KEY = "auth_token"
|
||||||
|
|
||||||
type JapeMiddlewareFunc func(jape.Handler) jape.Handler
|
type JapeMiddlewareFunc func(jape.Handler) jape.Handler
|
||||||
type HttpMiddlewareFunc func(http.Handler) http.Handler
|
type HttpMiddlewareFunc func(http.Handler) http.Handler
|
||||||
|
@ -154,6 +155,7 @@ func AuthMiddleware(options AuthMiddlewareOptions) func(http.Handler) http.Handl
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithValue(r.Context(), options.AuthContextKey, uint(userId))
|
ctx := context.WithValue(r.Context(), options.AuthContextKey, uint(userId))
|
||||||
|
ctx = context.WithValue(r.Context(), AUTH_TOKEN_CONTEXT_KEY, authToken)
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
|
Loading…
Reference in New Issue