diff options
-rw-r--r-- | auth.go | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -11,8 +11,9 @@ import ( "golang.org/x/crypto/bcrypt" ) +type userContextKey struct{} + const ( - userContextKey = "_user" sessionDuration = 86400 * 7 // 7 days loginQueryMarker = "next" ) @@ -25,7 +26,7 @@ func RequireAuth(next http.Handler) http.Handler { u, err := Q.GetUserById(r.Context(), s.UserID) if err == nil { // authenticated --> done - ctx := context.WithValue(r.Context(), userContextKey, u.ID) + ctx := context.WithValue(r.Context(), userContextKey{}, u.ID) next.ServeHTTP(w, r.WithContext(ctx)) return } @@ -125,5 +126,5 @@ func loginPage() http.HandlerFunc { } func userId(r *http.Request) int32 { - return r.Context().Value(userContextKey).(int32) + return r.Context().Value(userContextKey{}).(int32) } |