[PR #7904] [MERGED] feat: add trusted providers function #15871

Closed
opened 2026-04-13 10:16:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7904
Author: @Siumauricio
Created: 2/11/2026
Status: Merged
Merged: 2/18/2026
Merged by: @Bekacru

Base: canaryHead: feat/add-trusted-providers-fn


📝 Commits (10+)

  • 175d648 feat: enhance trusted providers functionality
  • aed5105 Merge branch 'canary' into feat/add-trusted-providers-fn
  • 322d21d test: add tests for request-dependent trustedProviders resolution
  • 9a7d650 test: update trustedProviders function to handle optional request parameter
  • 4c70ad4 Merge branch 'canary' into feat/add-trusted-providers-fn
  • 11c644e docs: enhance BetterAuthOptions type documentation for trustedProviders function to clarify handling of optional request parameter
  • 727cf77 test: add unit test for dynamic trustedProviders function to ensure request is passed correctly
  • a3af6ba test: update trustedProviders function tests to reflect correct call counts and request handling
  • b67eadb Merge branch 'canary' into feat/add-trusted-providers-fn
  • 8911911 Merge branch 'canary' into feat/add-trusted-providers-fn

📊 Changes

12 files changed (+247 additions, -24 deletions)

View changed files

📝 docs/content/docs/reference/options.mdx (+2 -2)
📝 packages/better-auth/src/api/routes/account.ts (+3 -4)
📝 packages/better-auth/src/api/routes/callback.ts (+3 -3)
📝 packages/better-auth/src/auth/base.ts (+2 -1)
📝 packages/better-auth/src/context/create-context.test.ts (+173 -0)
📝 packages/better-auth/src/context/create-context.ts (+3 -0)
📝 packages/better-auth/src/context/helpers.ts (+16 -0)
📝 packages/better-auth/src/oauth2/link-account.ts (+1 -3)
📝 packages/better-auth/src/plugins/one-tap/index.ts (+1 -1)
📝 packages/core/src/types/context.ts (+5 -0)
📝 packages/core/src/types/init-options.ts (+36 -4)
📝 packages/sso/src/routes/sso.ts (+2 -6)

📄 Description

Currently, we can add trustedOrigins, SSO, and SAML providers, but we cannot add trustedProviders dynamically, which breaks the dynamic of being able to use SAML, since in many cases we add a SAML provider but have to manually write the provider, which breaks the flow this is for https://github.com/Dokploy/dokploy

Link https://github.com/better-auth/better-auth/issues/6481#issuecomment-3620855211


Summary by cubic

Adds dynamic trustedProviders for account linking across OAuth, One Tap, and SSO. Providers resolve at init and on each request to support SAML without manual provider setup.

  • New Features

    • trustedProviders accepts a static array or async (request?) => string[]; resolved at init (request undefined) and per request; BetterAuthOptions/docs updated with examples and trustedOrigins-style behavior.
    • Added getTrustedProviders and AuthContext.trustedProviders; tests cover static, dynamic, empty, request-dependent lists and verify the Request is passed and re-resolved per request.
  • Refactors

    • Replaced direct reads with context.trustedProviders in account, OAuth callback, link-account, One Tap, and SSO routes.

Written for commit fe09e8894d. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7904 **Author:** [@Siumauricio](https://github.com/Siumauricio) **Created:** 2/11/2026 **Status:** ✅ Merged **Merged:** 2/18/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/add-trusted-providers-fn` --- ### 📝 Commits (10+) - [`175d648`](https://github.com/better-auth/better-auth/commit/175d648bad588584278cdd6e6435fa46263da9b5) feat: enhance trusted providers functionality - [`aed5105`](https://github.com/better-auth/better-auth/commit/aed5105b0cc1fff7e67cd606fdef5d690a14a281) Merge branch 'canary' into feat/add-trusted-providers-fn - [`322d21d`](https://github.com/better-auth/better-auth/commit/322d21d24a8018da66d1e11d339664daf87ef22b) test: add tests for request-dependent trustedProviders resolution - [`9a7d650`](https://github.com/better-auth/better-auth/commit/9a7d65010fe87924705f33fae87568dd9f4352ee) test: update trustedProviders function to handle optional request parameter - [`4c70ad4`](https://github.com/better-auth/better-auth/commit/4c70ad48c461064258d648e1ed47cb77ff64b94d) Merge branch 'canary' into feat/add-trusted-providers-fn - [`11c644e`](https://github.com/better-auth/better-auth/commit/11c644ebcb31435a8b753de9f89dec8ed2621c52) docs: enhance BetterAuthOptions type documentation for trustedProviders function to clarify handling of optional request parameter - [`727cf77`](https://github.com/better-auth/better-auth/commit/727cf775d97b59335eb3710a15c4924ad86e5867) test: add unit test for dynamic trustedProviders function to ensure request is passed correctly - [`a3af6ba`](https://github.com/better-auth/better-auth/commit/a3af6bae6c1c609e9e4a2b4985b5065973e3ce33) test: update trustedProviders function tests to reflect correct call counts and request handling - [`b67eadb`](https://github.com/better-auth/better-auth/commit/b67eadb3f29371a885ae8a6dcc8788e19223691e) Merge branch 'canary' into feat/add-trusted-providers-fn - [`8911911`](https://github.com/better-auth/better-auth/commit/8911911726de77c5b127ee516a29950355d53866) Merge branch 'canary' into feat/add-trusted-providers-fn ### 📊 Changes **12 files changed** (+247 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/reference/options.mdx` (+2 -2) 📝 `packages/better-auth/src/api/routes/account.ts` (+3 -4) 📝 `packages/better-auth/src/api/routes/callback.ts` (+3 -3) 📝 `packages/better-auth/src/auth/base.ts` (+2 -1) 📝 `packages/better-auth/src/context/create-context.test.ts` (+173 -0) 📝 `packages/better-auth/src/context/create-context.ts` (+3 -0) 📝 `packages/better-auth/src/context/helpers.ts` (+16 -0) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+1 -3) 📝 `packages/better-auth/src/plugins/one-tap/index.ts` (+1 -1) 📝 `packages/core/src/types/context.ts` (+5 -0) 📝 `packages/core/src/types/init-options.ts` (+36 -4) 📝 `packages/sso/src/routes/sso.ts` (+2 -6) </details> ### 📄 Description Currently, we can add trustedOrigins, SSO, and SAML providers, but we cannot add trustedProviders dynamically, which breaks the dynamic of being able to use SAML, since in many cases we add a SAML provider but have to manually write the provider, which breaks the flow this is for https://github.com/Dokploy/dokploy Link https://github.com/better-auth/better-auth/issues/6481#issuecomment-3620855211 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds dynamic trustedProviders for account linking across OAuth, One Tap, and SSO. Providers resolve at init and on each request to support SAML without manual provider setup. - **New Features** - trustedProviders accepts a static array or async (request?) => string[]; resolved at init (request undefined) and per request; BetterAuthOptions/docs updated with examples and trustedOrigins-style behavior. - Added getTrustedProviders and AuthContext.trustedProviders; tests cover static, dynamic, empty, request-dependent lists and verify the Request is passed and re-resolved per request. - **Refactors** - Replaced direct reads with context.trustedProviders in account, OAuth callback, link-account, One Tap, and SSO routes. <sup>Written for commit fe09e8894db6c160cbb7226b978e82aedd52448f. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 10:16:38 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15871