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

Add users table name explicitly to avoid naming conflict in query #1212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
golang.org/x/term v0.16.0
golang.org/x/text v0.14.0
gopkg.in/h2non/gock.v1 v1.1.2
gorm.io/driver/postgres v1.5.2
gorm.io/driver/postgres v1.5.4
gorm.io/gorm v1.25.5
gotest.tools/v3 v3.5.1
k8s.io/apimachinery v0.29.0
Expand Down Expand Up @@ -99,7 +99,7 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
234 changes: 4 additions & 230 deletions go.sum

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions vendor/github.com/jackc/pgx/v5/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion vendor/github.com/jackc/pgx/v5/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 12 additions & 16 deletions vendor/github.com/jackc/pgx/v5/batch.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 26 additions & 20 deletions vendor/github.com/jackc/pgx/v5/conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions vendor/github.com/jackc/pgx/v5/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading