diff --git a/pkg/internal/gap/server.go b/pkg/internal/gap/server.go index f522205..c2cff47 100644 --- a/pkg/internal/gap/server.go +++ b/pkg/internal/gap/server.go @@ -72,7 +72,7 @@ func InitializeToNexus() error { Name: "OTPs", Subjects: []string{FactorOtpPrefix + ">"}, Storage: nats.MemoryStorage, - MaxAge: 5 * time.Minute, + MaxAge: 30 * time.Minute, } _, err = Jt.AddStream(jetstreamCfg) if err != nil && !errors.Is(err, nats.ErrStreamNameAlreadyInUse) { diff --git a/pkg/internal/services/factors.go b/pkg/internal/services/factors.go index 08528a9..9cde2e6 100644 --- a/pkg/internal/services/factors.go +++ b/pkg/internal/services/factors.go @@ -119,11 +119,13 @@ func CheckFactor(factor models.AuthFactor, code string) error { ) case models.EmailPasswordFactor: identifier := fmt.Sprintf("%s%d", gap.FactorOtpPrefix, factor.ID) - sub, err := gap.Jt.PullSubscribe(identifier, "otp_validator") + sub, err := gap.Jt.PullSubscribe(identifier, "otp_validator", nats.BindStream("OTPs")) if err != nil { 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() msgs, err := sub.Fetch(1, nats.MaxWait(3*time.Second)) if err != nil {