summaryrefslogtreecommitdiff
path: root/auth.go
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--auth.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/auth.go b/auth.go
index c9797f7..2027827 100644
--- a/auth.go
+++ b/auth.go
@@ -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)
}