Skip to content

Commit

Permalink
fix(db): update user name field conditionally
Browse files Browse the repository at this point in the history
prevents name from flip-flopping between auth providers if it's
different on each platform. The name will not change from the one that
is used in the first login, even if a new provider is used with the same
email address and a different name.
  • Loading branch information
scottmckendry committed Aug 21, 2024
1 parent 4d5d7f2 commit 4d7761d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ func createUser(db *sql.DB, user *User) error {
}

func updateUser(db *sql.DB, user *User) error {
_, err := db.Exec(
"UPDATE users SET name = ?, discord_id = ?, github_id = ? WHERE email = ?",
_, err := db.Exec(`
UPDATE users
SET
name = CASE
WHEN name IS NULL THEN ?
ELSE name
END,
discord_id = ?,
github_id = ?
WHERE email = ?
`,
user.Name,
user.DiscordID,
user.GithubID,
Expand Down

0 comments on commit 4d7761d

Please sign in to comment.