From fed972fc16806df9cf6c209a90416485bb47b6bc Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 11 Oct 2024 19:37:20 +0800 Subject: [PATCH] :bug: Fix websocket connection when no auth provider panic --- pkg/internal/services/connections.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/internal/services/connections.go b/pkg/internal/services/connections.go index e716540..8fdf1bc 100644 --- a/pkg/internal/services/connections.go +++ b/pkg/internal/services/connections.go @@ -26,12 +26,15 @@ func ClientRegister(user models.Account, conn *websocket.Conn) uint64 { wsConn[user.ID][clientId] = conn wsMutex.Unlock() - pc, err := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider).GetGrpcConn() - if err == nil { - proto.NewStreamControllerClient(pc).EmitStreamEvent(context.Background(), &proto.StreamEventRequest{ - Event: "ClientRegister", - UserId: uint64(user.ID), - }) + srv := directory.GetServiceInstanceByType(hyper.ServiceTypeAuthProvider) + if srv != nil { + pc, err := srv.GetGrpcConn() + if err == nil { + _, _ = proto.NewStreamControllerClient(pc).EmitStreamEvent(context.Background(), &proto.StreamEventRequest{ + Event: "ClientRegister", + UserId: uint64(user.ID), + }) + } } return clientId