Files
stpweb/backend/graph/middleware.go
T
adamfandClaude Opus 5.5 4530cb8dc4
Test and deploy / test (push) Successful in 28s
Test and deploy / deploy (push) Successful in 31s
Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo,
keep short ones for security boundaries, upstream quirks and ordering
constraints, and record the convention in CLAUDE.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 20:49:03 +00:00

29 lines
719 B
Go

package graph
import (
"context"
"adam-french.co.uk/backend/services"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
// AuthContextMiddleware never rejects: a bad or missing token leaves the
// context anonymous and the directives decide. No refresh fallback.
func AuthContextMiddleware(auth *services.Auth, db *gorm.DB) gin.HandlerFunc {
return func(c *gin.Context) {
ctx := context.WithValue(c.Request.Context(), ginContextKey, c)
accessToken, err := c.Cookie("access_token")
if err == nil {
_, claims, err := auth.AuthenticateTokenWithClaims(db, accessToken)
if err == nil {
ctx = context.WithValue(ctx, userClaimsKey, claims)
}
}
c.Request = c.Request.WithContext(ctx)
c.Next()
}
}