From b235f52cfda7e871b6302ecf273789e17b8842ae Mon Sep 17 00:00:00 2001 From: garrettladley Date: Tue, 18 Jun 2024 18:51:05 -0400 Subject: [PATCH] =?UTF-8?q?=E2=98=A2=EF=B8=8F=20bug:=20on=20first=20user?= =?UTF-8?q?=20creation,=20user=20stored=20in=20state=20is=20null=20version?= =?UTF-8?q?=20(e.g.=20uuid:=200000-0000-0000-0000)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/entities/auth/base/transactions.go | 14 ++++++++------ backend/integrations/oauth/soth/sothic/sothic.go | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/entities/auth/base/transactions.go b/backend/entities/auth/base/transactions.go index 1dd839c5..01ecfb5e 100644 --- a/backend/entities/auth/base/transactions.go +++ b/backend/entities/auth/base/transactions.go @@ -13,9 +13,11 @@ func FindOrCreateUser(ctx context.Context, db *gorm.DB, user soth.User) (*models var sacUser models.User if err := db.WithContext(ctx).Where("email = ?", user.Email).First(&sacUser).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - if err := createUser(ctx, db, user.Into()); err != nil { + user, err := createUser(ctx, db, *user.Into()) + if err != nil { return nil, err } + return user, nil } else { return nil, err } @@ -24,7 +26,7 @@ func FindOrCreateUser(ctx context.Context, db *gorm.DB, user soth.User) (*models return &sacUser, nil } -func createUser(ctx context.Context, db *gorm.DB, user *models.User) error { +func createUser(ctx context.Context, db *gorm.DB, user models.User) (*models.User, error) { tx := db.WithContext(ctx).Begin() defer func() { if r := recover(); r != nil { @@ -32,16 +34,16 @@ func createUser(ctx context.Context, db *gorm.DB, user *models.User) error { } }() - if err := tx.Create(user).Error; err != nil { + if err := tx.Create(&user).Error; err != nil { tx.Rollback() - return err + return nil, err } welcomeTask := models.WelcomeTask{Name: user.Name, Email: user.Email} if err := tx.Create(&welcomeTask).Error; err != nil { tx.Rollback() - return err + return nil, err } - return tx.Commit().Error + return &user, tx.Commit().Error } diff --git a/backend/integrations/oauth/soth/sothic/sothic.go b/backend/integrations/oauth/soth/sothic/sothic.go index ff7c2a3f..17d896ac 100644 --- a/backend/integrations/oauth/soth/sothic/sothic.go +++ b/backend/integrations/oauth/soth/sothic/sothic.go @@ -353,16 +353,20 @@ func updateSessionValue(session *session.Session, key, value string) error { if _, err := gz.Write([]byte(value)); err != nil { return err } + if err := gz.Flush(); err != nil { return err } + if err := gz.Close(); err != nil { return err } + encrypted, err := encrypter(b.String()) if err != nil { return err } + session.Set(key, encrypted) return nil }