[GH-ISSUE #934] better auth social providers type #17138

Closed
opened 2026-04-15 15:06:01 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @draylegend on GitHub (Dec 18, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/934

Issue

TS2322: Type string is not assignable to type
'github' | 'apple' | 'discord' | 'facebook' | 'google' | 'microsoft' | 'spotify' | 'twitch' | 'twitter' | 'dropbox' | 'linkedin' | 'gitlab' | 'reddit'

auth-5DAdlxmK.d.ts(8131, 21): The expected type comes from property provider which is declared here on type

Prettify<{ provider: "github" | "apple" | "discord" | "facebook" | "google" | "microsoft" | "spotify" | "twitch" | "twitter" | "dropbox" | "linkedin" | "gitlab" | "reddit"; idToken?: { ...; } | undefined; callbackURL?: string | undefined; newUserCallbackURL?: string | undefined; errorCallbackURL?: string | undefined...

image

Describe the solution you'd like

I need the type BetterAuthSocialProviders or similar to properly annotate arguments/variables

  protected signInWith(provider: BetterAuthSocialProviders) {
    signIn.social({ provider });
  }
export type BetterAuthSocialProviders = 'google' | ...;
Originally created by @draylegend on GitHub (Dec 18, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/934 ### Issue ```ts TS2322: Type string is not assignable to type 'github' | 'apple' | 'discord' | 'facebook' | 'google' | 'microsoft' | 'spotify' | 'twitch' | 'twitter' | 'dropbox' | 'linkedin' | 'gitlab' | 'reddit' auth-5DAdlxmK.d.ts(8131, 21): The expected type comes from property provider which is declared here on type Prettify<{ provider: "github" | "apple" | "discord" | "facebook" | "google" | "microsoft" | "spotify" | "twitch" | "twitter" | "dropbox" | "linkedin" | "gitlab" | "reddit"; idToken?: { ...; } | undefined; callbackURL?: string | undefined; newUserCallbackURL?: string | undefined; errorCallbackURL?: string | undefined... ``` ![image](https://github.com/user-attachments/assets/4ad07892-29ed-4f9d-92ab-0b7dcf8f991b) ### Describe the solution you'd like I need the type `BetterAuthSocialProviders` or similar to properly annotate arguments/variables ```ts protected signInWith(provider: BetterAuthSocialProviders) { signIn.social({ provider }); } ``` ```ts export type BetterAuthSocialProviders = 'google' | ...; ```
GiteaMirror added the locked label 2026-04-15 15:06:01 -05:00
Author
Owner

@emroot commented on GitHub (Dec 18, 2024):

can you use this instead?
auth being your auth config.

type Providers = keyof typeof auth.options.socialProviders;

This will return only the providers that you are actually using.

<!-- gh-comment-id:2552041675 --> @emroot commented on GitHub (Dec 18, 2024): can you use this instead? auth being your auth config. ``` type Providers = keyof typeof auth.options.socialProviders; ``` This will return only the providers that you are actually using.
Author
Owner

@daveycodez commented on GitHub (Dec 18, 2024):

That would be doable but it would keep the application's codebase cleaner to have an import type SocialProviders coming out of the lib.

<!-- gh-comment-id:2552093310 --> @daveycodez commented on GitHub (Dec 18, 2024): That would be doable but it would keep the application's codebase cleaner to have an import type SocialProviders coming out of the lib.
Author
Owner

@emroot commented on GitHub (Dec 18, 2024):

Yeah I think that would be great to have if you need all the providers but this approach will limit to only the providers you are actually using, less error prone for someone to use a provider that is not implemented.

<!-- gh-comment-id:2552170770 --> @emroot commented on GitHub (Dec 18, 2024): Yeah I think that would be great to have if you need all the providers but this approach will limit to only the providers you are actually using, less error prone for someone to use a provider that is not implemented.
Author
Owner

@draylegend commented on GitHub (Dec 19, 2024):

@emroot thank you! Actually even better than I could imagine! In fact I just need already configured providers reducing the providers' list.

@daveycodez interesting point. The extra line suggested by @emroot doesn't hurt me ^^

<!-- gh-comment-id:2553283935 --> @draylegend commented on GitHub (Dec 19, 2024): @emroot thank you! Actually even better than I could imagine! In fact I just need already configured providers reducing the providers' list. @daveycodez interesting point. The extra line suggested by @emroot doesn't hurt me ^^
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17138