[PR #8818] [MERGED] fix(sso): provisionUser inconsistency and option to run on every login #25135

Closed
opened 2026-04-15 22:44:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8818
Author: @formatlos
Created: 3/28/2026
Status: Merged
Merged: 3/30/2026
Merged by: @gustavovalverde

Base: mainHead: fix/provision-user-run-on-every-login


📝 Commits (2)

  • 6f20736 fix(sso): add register-only check to provisionUser
  • f7acec8 fix(sso): add config option to provisionUser on every login

📊 Changes

5 files changed (+399 additions, -6 deletions)

View changed files

📝 docs/content/docs/plugins/sso.mdx (+11 -3)
📝 packages/sso/src/oidc.test.ts (+137 -0)
📝 packages/sso/src/routes/sso.ts (+12 -3)
📝 packages/sso/src/saml.test.ts (+229 -0)
📝 packages/sso/src/types.ts (+10 -0)

📄 Description

closes https://github.com/better-auth/better-auth/issues/8630

Previously a isRegister check was added to prevent provisionUser from running on every login to the OIDC provider. This PR does add this behaviour to SAML as well to remove this inconsistency.

As some users (including me) will have the need to update the users profile info also for returning users, I also added an option provisionUserOnEveryLogin: true, so that provisionUser is called on every login.


Summary by cubic

Aligns SAML with OIDC so provisionUser runs only on first sign-in by default, and adds provisionUserOnEveryLogin to call it on every login when needed. This enables reliable profile sync from upstream IdPs while keeping safe defaults.

  • New Features

    • Added provisionUserOnEveryLogin in SSOOptions; when true, provisionUser runs on every sign-in across OIDC and SAML.
    • Updated docs with usage, defaults, and idempotency guidance.
  • Bug Fixes

    • SAML now matches OIDC: call provisionUser only on registration by default.
    • Added OIDC and SAML tests to cover first vs subsequent logins.

Written for commit f7acec8e95. 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/8818 **Author:** [@formatlos](https://github.com/formatlos) **Created:** 3/28/2026 **Status:** ✅ Merged **Merged:** 3/30/2026 **Merged by:** [@gustavovalverde](https://github.com/gustavovalverde) **Base:** `main` ← **Head:** `fix/provision-user-run-on-every-login` --- ### 📝 Commits (2) - [`6f20736`](https://github.com/better-auth/better-auth/commit/6f207365029dab4db038fafd0cc931682daff13b) fix(sso): add register-only check to provisionUser - [`f7acec8`](https://github.com/better-auth/better-auth/commit/f7acec8e9596984510d85b3743a03c238e2f55bd) fix(sso): add config option to provisionUser on every login ### 📊 Changes **5 files changed** (+399 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/sso.mdx` (+11 -3) 📝 `packages/sso/src/oidc.test.ts` (+137 -0) 📝 `packages/sso/src/routes/sso.ts` (+12 -3) 📝 `packages/sso/src/saml.test.ts` (+229 -0) 📝 `packages/sso/src/types.ts` (+10 -0) </details> ### 📄 Description closes https://github.com/better-auth/better-auth/issues/8630 Previously a isRegister check was added to prevent provisionUser from running on every login to the OIDC provider. This PR does add this behaviour to SAML as well to remove this inconsistency. As some users (including me) will have the need to update the users profile info also for returning users, I also added an option `provisionUserOnEveryLogin: true`, so that `provisionUser` is called on every login. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Aligns SAML with OIDC so `provisionUser` runs only on first sign-in by default, and adds `provisionUserOnEveryLogin` to call it on every login when needed. This enables reliable profile sync from upstream IdPs while keeping safe defaults. - **New Features** - Added `provisionUserOnEveryLogin` in `SSOOptions`; when true, `provisionUser` runs on every sign-in across OIDC and SAML. - Updated docs with usage, defaults, and idempotency guidance. - **Bug Fixes** - SAML now matches OIDC: call `provisionUser` only on registration by default. - Added OIDC and SAML tests to cover first vs subsequent logins. <sup>Written for commit f7acec8e9596984510d85b3743a03c238e2f55bd. 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-15 22:44:10 -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#25135