Skip to content

Commit b7767f9

Browse files
committed
fix: duplicate user_code update
1 parent 111eea0 commit b7767f9

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
@@ -763,17 +763,15 @@ func (p *Persister) UpdateAndInvalidateUserCodeSessionByRequestID(ctx context.Co
763763
ctx, span := p.r.Tracer(ctx).Tracer().Start(ctx, "persistence.sql.UpdateAndInvalidateUserCodeSession")
764764
defer otelx.End(span, &err)
765765

766-
// TODO(nsklikas): afaict this is supposed to return an error if no rows were updated, but this is not the actual behavior.
767-
// We need to either fix this OR do a select -> check -> update (this would require 2 queries instead of 1).
768-
/* #nosec G201 table is static */
769-
return sqlcon.HandleError(
770-
p.Connection(ctx).
771-
RawQuery(
772-
fmt.Sprintf("UPDATE %s SET active=false, challenge_id=? WHERE request_id=? AND nid = ? AND active=true", OAuth2RequestSQL{Table: sqlTableUserCode}.TableName()),
773-
challenge_id,
774-
request_id,
775-
p.NetworkID(ctx),
776-
).
777-
Exec(),
778-
)
766+
if count, err := p.Connection(ctx).RawQuery(
767+
fmt.Sprintf("UPDATE %s SET active=false, challenge_id=? WHERE request_id=? AND nid = ? AND active=true", OAuth2RequestSQL{Table: sqlTableUserCode}.TableName()),
768+
challenge_id,
769+
request_id,
770+
p.NetworkID(ctx),
771+
).ExecWithCount(); count == 0 && err == nil {
772+
return errorsx.WithStack(x.ErrNotFound)
773+
} else if err != nil {
774+
return sqlcon.HandleError(err)
775+
}
776+
return nil
779777
}

0 commit comments

Comments
 (0)