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