From b2c70a608f6fdc10a5c6d4d9c5417e12ec41a8b7 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 16 Oct 2024 16:21:15 +0200 Subject: [PATCH 1/2] Makes user phone Mongo Index a sparse index, as way to accept null values --- db/helpers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/helpers.go b/db/helpers.go index 031030c..653c0bd 100644 --- a/db/helpers.go +++ b/db/helpers.go @@ -116,7 +116,7 @@ func (ms *MongoStorage) createIndexes() error { // create an index for the 'phone' field on users userPhoneIndex := mongo.IndexModel{ Keys: bson.D{{Key: "phone", Value: 1}}, // 1 for ascending order - Options: options.Index().SetUnique(true), + Options: options.Index().SetSparse(true), } if _, err := ms.users.Indexes().CreateOne(ctx, userPhoneIndex); err != nil { return fmt.Errorf("failed to create index on phone for users: %w", err) From 2828a7bfc4c1adf5a0d17d23ddfdece1c03c4842 Mon Sep 17 00:00:00 2001 From: emmdim Date: Wed, 16 Oct 2024 16:21:40 +0200 Subject: [PATCH 2/2] Fixes SMTP authentication data bug --- notifications/smtp/smtp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifications/smtp/smtp.go b/notifications/smtp/smtp.go index 46d0498..68a08c6 100644 --- a/notifications/smtp/smtp.go +++ b/notifications/smtp/smtp.go @@ -51,7 +51,7 @@ func (se *SMTPEmail) New(rawConfig any) error { // set configuration in struct se.config = config // init SMTP auth - if se.config.SMTPUsername == "" || se.config.SMTPPassword == "" { + if se.config.SMTPUsername != "" && se.config.SMTPPassword != "" { se.auth = smtp.PlainAuth("", se.config.SMTPUsername, se.config.SMTPPassword, se.config.SMTPServer) } return nil