fix auth interceptors in task and user services;

This commit is contained in:
timka
2025-12-17 18:04:49 +03:00
parent 6fd31915b9
commit 400e26cfff
4 changed files with 52 additions and 1 deletions
+7
View File
@@ -17,6 +17,7 @@ import (
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
)
@@ -46,6 +47,12 @@ func (s *Server) Start() error {
}
s.db = db
authConn, err := grpc.Dial(s.config.AuthSvcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("failed to connect to auth service: %w", err)
}
s.authConn = authConn
if err := s.registerGRPCServices(); err != nil {
return fmt.Errorf("failed to register gRPC services: %w", err)
}
+3 -1
View File
@@ -21,6 +21,7 @@ type Config struct {
DBPassword string
DBName string
JWTSecret string
AuthSvcAddr string
}
func Load() (*Config, error) {
@@ -37,6 +38,7 @@ func Load() (*Config, error) {
DBPassword: getEnv("POSTGRES_PASSWORD", "postgres"),
DBName: getEnv("POSTGRES_DATABASE", "postgres"),
JWTSecret: getEnv("JWT_SECRET", "your-secret-key-change-in-production"),
AuthSvcAddr: getEnv("AUTH_SVC_ADDR", "localhost:50051"),
}, nil
}
@@ -73,4 +75,4 @@ func (c Config) BuildPostgresConnStr() string {
func (c Config) BuildPostgresDSN() string {
return fmt.Sprintf("postgresql://%s:%s@%s/%s?sslmode=disable",
c.DBUser, c.DBPassword, net.JoinHostPort(c.DBHost, strconv.Itoa(c.DBPort)), c.DBName)
}
}
+13
View File
@@ -17,6 +17,7 @@ import (
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/reflection"
)
@@ -46,6 +47,12 @@ func (s *Server) Start() error {
}
s.db = db
authConn, err := grpc.Dial(s.config.AuthSvcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return fmt.Errorf("failed to connect to auth service: %w", err)
}
s.authConn = authConn
if err := s.registerGRPCServices(); err != nil {
return fmt.Errorf("failed to register gRPC services: %w", err)
}
@@ -100,5 +107,11 @@ func (s *Server) Stop() {
}
}
if s.authConn != nil {
if err := s.authConn.Close(); err != nil {
log.Printf("failed to close auth connection: %v", err)
}
}
log.Println("user server stopped")
}