Add createJWTMiddleware helper that sets database.Users object in context, matching the original main.go JWT middleware behavior. This fixes 'authentication context error' panics in handlers that call MustGetAuthenticatedUser. Changes: - Add createJWTMiddleware() in router.go - Update all route files to use the helper - Set user claims AND database.Users object in context
17 lines
484 B
Go
17 lines
484 B
Go
package router
|
|
|
|
func registerAnalyticsRoutes(cfg *Config) {
|
|
e := cfg.Echo
|
|
|
|
// JWT middleware for protected routes
|
|
jwtMiddleware := createJWTMiddleware(cfg)
|
|
|
|
protected := e.Group("/api", jwtMiddleware)
|
|
|
|
// Analytics routes
|
|
analytics := protected.Group("/analytics")
|
|
analytics.GET("/reading-stats", cfg.AnalyticsHandler.GetReadingStats)
|
|
analytics.GET("/device-usage", cfg.AnalyticsHandler.GetDeviceUsage)
|
|
analytics.GET("/popular-books", cfg.AnalyticsHandler.GetPopularBooks)
|
|
}
|