Question: How to properly register or disable SSO providers in BetterAuth? #2862

Open
opened 2026-03-13 10:24:22 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @Waliya-noor on GitHub (Feb 12, 2026).

Hi! I'm new to BetterAuth and I need some clarification on how SSO provider registration is supposed to work.
Right now, I see that providers get registered in the auth initialization code. My confusion is:

If I put the provider registration directly in the code, it will register every time the app starts.
→ How am I supposed to register providers in a way that doesn't auto‑register them on every run?

→ How do I disable or “deregister” a provider?
I didn’t find any function or documentation explaining how to remove a provider once added.

What seems suitable in my case is the list of providers come from configuration (like env variables), adding or removing the config objects in the list registers or deregisters the providers. Is there another recommended pattern?

I basically want to understand the correct way to manage providers so that I can enable or disable them depending on the environment without them always being registered automatically and on every run.

Originally created by @Waliya-noor on GitHub (Feb 12, 2026). Hi! I'm new to BetterAuth and I need some clarification on how SSO provider registration is supposed to work. Right now, I see that providers get registered in the auth initialization code. My confusion is: If I put the provider registration directly in the code, it will register every time the app starts. → How am I supposed to register providers in a way that doesn't auto‑register them on every run? → How do I disable or “deregister” a provider? I didn’t find any function or documentation explaining how to remove a provider once added. What seems suitable in my case is the list of providers come from configuration (like env variables), adding or removing the config objects in the list registers or deregisters the providers. Is there another recommended pattern? I basically want to understand the correct way to manage providers so that I can enable or disable them depending on the environment without them always being registered automatically and on every run.
GiteaMirror added the question label 2026-03-13 10:24:22 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Feb 12, 2026):

To manage SSO provider registration effectively in BetterAuth, you can follow these recommendations:

  1. Conditional Registration: To avoid auto-registering providers each time the application starts, consider utilizing a configuration object (like environment variables). You can check for the existence of specific variables in your auth initialization code to conditionally register providers. This way, you can enable or disable providers based on your environment.

  2. Deregistering Providers: The current documentation does not specify a built-in function to deregister SSO providers once they have been added. You could implement a solution where your application checks the current configuration against a list of registered providers and handles deregistration logic accordingly.

  3. Default Provider: You can set a default SSO provider to be used when no matching provider is found. This is helpful for local testing without requiring every provider to be registered.

For example, your configuration might look like this:

import { betterAuth } from "better-auth";
import { sso } from "@better-auth/sso";

const providers = process.env.SSO_PROVIDERS ? JSON.parse(process.env.SSO_PROVIDERS) : [];

const auth = betterAuth({
  plugins: [
    sso({
      providers: providers,
      // additional sso configuration
    }),
  ],
});

This approach uses an env variable to define which SSO providers to use.

Is there a specific provider you plan to work with that you're unsure about? Let me know how I can assist further!

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Feb 12, 2026): To manage SSO provider registration effectively in BetterAuth, you can follow these recommendations: 1. **Conditional Registration**: To avoid auto-registering providers each time the application starts, consider utilizing a configuration object (like environment variables). You can check for the existence of specific variables in your auth initialization code to conditionally register providers. This way, you can enable or disable providers based on your environment. 2. **Deregistering Providers**: The current documentation does not specify a built-in function to deregister SSO providers once they have been added. You could implement a solution where your application checks the current configuration against a list of registered providers and handles deregistration logic accordingly. 3. **Default Provider**: You can set a default SSO provider to be used when no matching provider is found. This is helpful for local testing without requiring every provider to be registered. For example, your configuration might look like this: ```typescript import { betterAuth } from "better-auth"; import { sso } from "@better-auth/sso"; const providers = process.env.SSO_PROVIDERS ? JSON.parse(process.env.SSO_PROVIDERS) : []; const auth = betterAuth({ plugins: [ sso({ providers: providers, // additional sso configuration }), ], }); ``` This approach uses an env variable to define which SSO providers to use. Is there a specific provider you plan to work with that you're unsure about? Let me know how I can assist further! _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2862