add interceptors to task and competition services

This commit is contained in:
timka
2025-12-17 17:58:58 +03:00
parent c5ec20121b
commit 6fd31915b9
3 changed files with 11 additions and 9 deletions
+3 -1
View File
@@ -69,7 +69,9 @@ func (s *Server) registerGRPCServices() error {
authClient := authpb.NewAuthServiceClient(s.authConn)
authInterceptor := interceptor.NewAuthInterceptor(authClient)
s.grpcServer = grpc.NewServer()
s.grpcServer = grpc.NewServer(
grpc.UnaryInterceptor(authInterceptor.Unary()),
)
taskRepo := taskPostgresRepo.NewTaskRepository(s.db)
+8 -3
View File
@@ -8,10 +8,11 @@ import (
"datarush/internal/user/config"
grpcHandlers "datarush/internal/user/handler/grpc"
"datarush/internal/user/middleware"
userPostgresRepo "datarush/internal/user/repository/postgres"
"datarush/internal/user/service"
authpb "datarush/pkg/api/auth"
pb "datarush/pkg/api/user"
"datarush/pkg/interceptor"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
@@ -29,6 +30,7 @@ type Server struct {
grpcServer *grpc.Server
config *config.Config
db *sqlx.DB
authConn *grpc.ClientConn
}
func New(cfg *config.Config) *Server {
@@ -64,8 +66,11 @@ func (s *Server) Start() error {
}
func (s *Server) registerGRPCServices() error {
authClient := authpb.NewAuthServiceClient(s.authConn)
authInterceptor := interceptor.NewAuthInterceptor(authClient)
s.grpcServer = grpc.NewServer(
grpc.UnaryInterceptor(middleware.AuthInterceptor(s.config.JWTSecret)),
grpc.UnaryInterceptor(authInterceptor.Unary()),
)
userRepo := userPostgresRepo.NewUserRepository(s.db)
@@ -96,4 +101,4 @@ func (s *Server) Stop() {
}
log.Println("user server stopped")
}
}