Skip to content

Commit 87c6315

Browse files
committed
fix: duplicate user_code update
1 parent 1f55a42 commit 87c6315

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

persistence/sql/persister_oauth2.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -700,17 +700,15 @@ func (p *Persister) UpdateAndInvalidateUserCodeSessionByRequestID(ctx context.Co
700700
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.UpdateAndInvalidateUserCodeSession")
701701
defer otelx.End(span, &err)
702702

703-
// TODO(nsklikas): afaict this is supposed to return an error if no rows were updated, but this is not the actual behavior.
704-
// We need to either fix this OR do a select -> check -> update (this would require 2 queries instead of 1).
705-
/* #nosec G201 table is static */
706-
return sqlcon.HandleError(
707-
p.Connection(ctx).
708-
RawQuery(
709-
fmt.Sprintf("UPDATE %s SET active=false, challenge_id=? WHERE request_id=? AND nid = ? AND active=true", OAuth2RequestSQL{Table: sqlTableUserCode}.TableName()),
710-
challenge_id,
711-
request_id,
712-
p.NetworkID(ctx),
713-
).
714-
Exec(),
715-
)
703+
if count, err := p.Connection(ctx).RawQuery(
704+
fmt.Sprintf("UPDATE %s SET active=false, challenge_id=? WHERE request_id=? AND nid = ? AND active=true", OAuth2RequestSQL{Table: sqlTableUserCode}.TableName()),
705+
challenge_id,
706+
request_id,
707+
p.NetworkID(ctx),
708+
).ExecWithCount(); count == 0 && err == nil {
709+
return errorsx.WithStack(x.ErrNotFound)
710+
} else if err != nil {
711+
return sqlcon.HandleError(err)
712+
}
713+
return nil
716714
}

0 commit comments

Comments
 (0)