Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

better-auth adapter: update() with compound where fails (deviceAuthorization verify-claim) — no updateMany fallback

オープン 初心者向け
#2,694 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript

調査の方向性

packages/auth-adapters/better-auth/src/adapter.ts から始めてください。convertWhereClause() (L47-90) と update() (L146-152) を読み、そのすぐ下にある updateMany() の実装と比較してください。変換された where が単一のトップレベル一意セレクタであるかどうかを判断し、非一意の複合を updateMany 経由でルーティングしてください。オプションで一意フィールドによる再読み取りを行ってください。DeviceCode 上の deviceAuthorization verify ステップで再現してください。その update が 'At least one unique field must be set at where' を発生させなくなり、アダプタのテストが通ったら完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

@zenstackhq/better-auth's update() forwards a compound (AND) where straight to ZenStack ORM update(), which requires a unique field at the top level of where. Any better-auth flow that updates by a multi-condition where therefore fails before SQL runs. This is now hit in normal usage by better-auth's deviceAuthorization plugin.

Environment
  • @zenstackhq/better-auth: 3.3.3 and 3.7.2 (latest) — same behavior
  • better-auth: 1.6.12 (regression triggered by >= 1.6.11)
  • ZenStack ORM 3.x, provider sqlite/postgresql
Repro
  1. Use zenstackAdapter as the better-auth database.
  2. Enable the deviceAuthorization plugin.
  3. Sign in, then open GET /device?user_code=... (verify step).
  4. Error:
    Invalid update args for model "DeviceCode": Validation error:
    At least one unique field or field set must be set at "where"
    
Root cause

better-auth >=1.6.11 added a verify-time ownership claim that updates with a compound where { id, status: "pending", userId: null } (https://github.com/better-auth/better-auth/blob/a6f38c72ee3423ae80b0595fec3b4a61158c374d/packages/better-auth/src/plugins/device-authorization/routes.ts#L144-L154).
The adapter's convertWhereClause() turns >=2 conditions into { AND: [...] } (https://github.com/zenstackhq/zenstack/blob/f41a1f6e4ae08af29bff3d2b3d8cde980708c214/packages/auth-adapters/better-auth/src/adapter.ts#L47-L90), and update() calls modelDb.update({ where }) unconditionally (https://github.com/zenstackhq/zenstack/blob/f41a1f6e4ae08af29bff3d2b3d8cde980708c214/packages/auth-adapters/better-auth/src/adapter.ts#L146-L152). ORM update() rejects the nested unique.

Suggested fix

In update(), when the converted where is not a single top-level unique selector, fall back to the existing updateMany() (then optionally re-read by the unique field) — mirroring how better-auth's own Prisma adapter handles non-unique update where. The adapter already implements updateMany() right below update().

主要言語
TypeScript
スター
2.9k
フォーク
157
平均マージ
11時間 42分
マージ済み PR(30日)
20

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

zenstackhq/zenstack のほかの issue

zenstackhq/zenstack の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。