add interceptors to task and competition services
This commit is contained in:
@@ -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,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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user