A community based topic aggregation platform built on atproto
at main 951 B view raw
1package comments 2 3import ( 4 "Coves/internal/api/middleware" 5 "net/http" 6) 7 8// OptionalAuthMiddleware wraps the existing OptionalAuth middleware from the middleware package. 9// This ensures comment handlers can access viewer identity when available, but don't require authentication. 10// 11// Usage in router setup: 12// 13// commentHandler := comments.NewGetCommentsHandler(commentService) 14// router.Handle("/xrpc/social.coves.feed.getComments", 15// comments.OptionalAuthMiddleware(authMiddleware, commentHandler.HandleGetComments)) 16// 17// The middleware extracts the viewer DID from the Authorization header if present and valid, 18// making it available via middleware.GetUserDID(r) in the handler. 19// If no valid token is present, the request continues as anonymous (empty DID). 20func OptionalAuthMiddleware(authMiddleware *middleware.OAuthAuthMiddleware, next http.HandlerFunc) http.Handler { 21 return authMiddleware.OptionalAuth(http.HandlerFunc(next)) 22}