[OIDC] Schema is missing foreign key references #1758

Closed
opened 2026-03-13 09:01:20 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @julen on GitHub (Aug 22, 2025).

Steps to reproduce:

  1. Install OIDC plugin
  2. Run bunx @better-auth/cli generate
  3. Check generated SQL. None of the oauth* tables contain foreign key references.

The docs mention FK references should be there, cf. d3c9496a72/docs/content/docs/plugins/oidc-provider.mdx (L384)

The schema has no references defined though: 577cfb4ab3/packages/better-auth/src/plugins/oidc-provider/schema.ts

I understand the schema is incomplete, but just wanted to raise the issue to confirm expectations before opening a PR with the fix.

Originally created by @julen on GitHub (Aug 22, 2025). Steps to reproduce: 1. Install OIDC plugin 2. Run `bunx @better-auth/cli generate` 3. Check generated SQL. None of the `oauth*` tables contain foreign key references. The docs mention FK references should be there, cf. https://github.com/better-auth/better-auth/blob/d3c9496a7286fd4f459279382b518271924185cd/docs/content/docs/plugins/oidc-provider.mdx?plain=1#L384 The schema has no references defined though: https://github.com/better-auth/better-auth/blob/577cfb4ab3b16d22f36892c0e843f36abcee80c3/packages/better-auth/src/plugins/oidc-provider/schema.ts I understand the schema is incomplete, but just wanted to raise the issue to confirm expectations before opening a PR with the fix.
GiteaMirror added the plugin label 2026-03-13 09:01:20 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 22, 2025):

Hi @julen! I'm Dosu and I’m helping the better-auth team.

You're correct—the OIDC plugin schema currently does not define foreign key references for its oauth* tables, even though the documentation suggests they should be present. This isn't intentional; it's an incomplete implementation and not a design decision. There are no technical blockers for adding FK references, but be aware that some features like Trusted Clients previously required removing certain constraints, and the system doesn't enforce them right now—so double-check for edge cases if you add them source.

Recent improvements elsewhere in Better Auth have added FK references and onDelete cascade behavior to other tables, and maintainers have acknowledged the schema is incomplete and intend to fix it source. A PR to add FK references to the OIDC schema would be appropriate and likely welcomed. For best practices, use explicit .references() methods in your schema definitions, as seen in other parts of the codebase source.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 22, 2025): <!-- Greeting --> Hi @julen! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're correct—the OIDC plugin schema currently does not define foreign key references for its `oauth*` tables, even though the documentation suggests they should be present. This isn't intentional; it's an incomplete implementation and not a design decision. There are no technical blockers for adding FK references, but be aware that some features like Trusted Clients previously required removing certain constraints, and the system doesn't enforce them right now—so double-check for edge cases if you add them [source](https://github.com/better-auth/better-auth/issues/2876#issuecomment-3095560783). Recent improvements elsewhere in Better Auth have added FK references and `onDelete cascade` behavior to other tables, and maintainers have acknowledged the schema is incomplete and intend to fix it [source](https://github.com/better-auth/better-auth/pull/3906). A PR to add FK references to the OIDC schema would be appropriate and likely welcomed. For best practices, use explicit `.references()` methods in your schema definitions, as seen in other parts of the codebase [source](https://github.com/better-auth/better-auth/issues/3310#issuecomment-3049894666). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9b6f3a3a-35d4-47fb-8427-9444eedb93f6?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4162)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1758