| 3488 | var ErrAPIKeyNotFound = errors.New("api key not found") |
| 3489 | |
| 3490 | func (s *Store) DeleteAPIKey(ctx context.Context, keyID, userID string) error { |
| 3491 | tag, err := s.pool.Exec(ctx, |
| 3492 | `UPDATE api_keys SET revoked_at = now() WHERE id = $1 AND user_id = $2 AND revoked_at IS NULL`, keyID, userID, |
| 3493 | ) |
| 3494 | if err != nil { |
| 3495 | return err |
| 3496 | } |
| 3497 | if tag.RowsAffected() == 0 { |
| 3498 | return ErrAPIKeyNotFound |
| 3499 | } |
| 3500 | return nil |
| 3501 | } |
| 3502 | |
| 3503 | // GetUserByAPIKey authenticates a bearer token and returns the owning |
| 3504 | // user. Rejects revoked keys and time-expired keys; touches last_used_at |