Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

☢️ bug: zero valued user being returned on account creation #1053

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions backend/entities/auth/base/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -24,24 +26,24 @@ 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 {
tx.Rollback()
}
}()

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
}
4 changes: 4 additions & 0 deletions backend/integrations/oauth/soth/sothic/sothic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading