🐛 Unsubscribe the stream after used the stream to validate code
This commit is contained in:
parent
e4ba72725e
commit
0dbc30d53c
@ -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,
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user