From 0dbc30d53cb5485779088a81fa30e0a73ed63c35 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 27 Jan 2025 16:31:15 +0800 Subject: [PATCH] :bug: Unsubscribe the stream after used the stream to validate code --- pkg/internal/gap/server.go | 4 ++-- pkg/internal/services/factors.go | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/internal/gap/server.go b/pkg/internal/gap/server.go index c2cff47..7cb493d 100644 --- a/pkg/internal/gap/server.go +++ b/pkg/internal/gap/server.go @@ -25,7 +25,7 @@ var ( ) const ( - FactorOtpPrefix = "passport.otp." + FactorOtpPrefix = "otp." ) func InitializeToNexus() error { @@ -70,7 +70,7 @@ func InitializeToNexus() error { jetstreamCfg := &nats.StreamConfig{ Name: "OTPs", - Subjects: []string{FactorOtpPrefix + ">"}, + Subjects: []string{fmt.Sprintf("%s>", FactorOtpPrefix)}, Storage: nats.MemoryStorage, MaxAge: 30 * time.Minute, } diff --git a/pkg/internal/services/factors.go b/pkg/internal/services/factors.go index 9cde2e6..5d57d86 100644 --- a/pkg/internal/services/factors.go +++ b/pkg/internal/services/factors.go @@ -124,8 +124,7 @@ func CheckFactor(factor models.AuthFactor, code string) error { log.Error().Err(err).Msg("Error subscribing to subject when validating factor code...") return fmt.Errorf("error subscribing to subject: %v", err) } - // ChatGPT said the subscription will be reused, so we don't need to unsubscribe - // defer sub.Unsubscribe() + defer sub.Unsubscribe() msgs, err := sub.Fetch(1, nats.MaxWait(3*time.Second)) if err != nil {