Skip to content

Commit

Permalink
Remove subquery to fix uniqely reference users table Add users table …
Browse files Browse the repository at this point in the history
…name

This fixes multiple times reference of same table in a query
and which was creating conflict

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 committed Jan 25, 2024
1 parent 8fdd25b commit eb4e013
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions api/pkg/auth/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,9 @@ func (r *request) insertData(gitUser goth.User, code, provider string) error {
var acc model.Account
var user model.User

userQuery := r.db.Model(&model.User{}).
Where("email = ?", gitUser.Email)

// Check if user exist
err := userQuery.First(&user).Error
err := r.db.Model(&model.User{}).
Where("email = ?", gitUser.Email).First(&user).Error

// If email doesn't exists in users table
if err != nil {
Expand Down Expand Up @@ -153,8 +151,8 @@ func (r *request) insertData(gitUser goth.User, code, provider string) error {
}
} else { // when the email of user already exists
// Update the users table with the auth code
if err := userQuery.Update("code", code).Error; err != nil {
r.log.Error(err)
if err := r.db.Model(&model.User{}).
Where("email = ?", gitUser.Email).Update("code", code).Error; err != nil {
return err
}

Expand Down

0 comments on commit eb4e013

Please sign in to comment.