[GH-ISSUE #4184] Suboptimal return type for auth.api.signInSocial #27177

Closed
opened 2026-04-17 18:01:50 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Stadly on GitHub (Aug 23, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4184

Originally assigned to: @Kinfe123 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

export const auth = betterAuth({ ... });
const response = await auth.api.signInSocial({ ... });

Current vs. Expected behavior

Take a look at the type of response. I think redirect should not be boolean, but true and false in each of the cases.

Image

That way, the property can be used for type narrowing:

if(response.redirect) {
  // response is { url: string; redirect: true; }
} else {
  // response is { redirect: false; token: string; url: undefined; ... }
}

What version of Better Auth are you using?

1.3.7

System info

System:
    OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
    Memory: 632.90 MB / 15.23 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash

Which area(s) are affected? (Select all that apply)

Types

Auth config (if applicable)


Additional context

No response

Originally created by @Stadly on GitHub (Aug 23, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4184 Originally assigned to: @Kinfe123 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```ts export const auth = betterAuth({ ... }); const response = await auth.api.signInSocial({ ... }); ``` ### Current vs. Expected behavior Take a look at the type of `response`. I think `redirect` should not be `boolean`, but `true` and `false` in each of the cases. <img width="475" height="428" alt="Image" src="https://github.com/user-attachments/assets/00046e9d-25d8-48af-8790-d2fbb399ecf1" /> That way, the property can be used for type narrowing: ```ts if(response.redirect) { // response is { url: string; redirect: true; } } else { // response is { redirect: false; token: string; url: undefined; ... } } ``` ### What version of Better Auth are you using? 1.3.7 ### System info ```bash System: OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm) CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz Memory: 632.90 MB / 15.23 GB Container: Yes Shell: 5.2.15 - /bin/bash ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-17 18:01:50 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Aug 24, 2025):

Yeah currently the auth.api.signInSocial method returns a union type where redirect is always typed as boolean, which prevents proper type narrowing and also prevents descriminated union as you mentioned. we can do as const litral on returns but i have to make sure this wont introduce a breaking change using it with better-call but will be a good thing to have. will check on this.

<!-- gh-comment-id:3218146288 --> @Kinfe123 commented on GitHub (Aug 24, 2025): Yeah currently the `auth.api.signInSocial` method returns a union type where redirect is always typed as boolean, which prevents proper type narrowing and also prevents descriminated union as you mentioned. we can do `as const` litral on returns but i have to make sure this wont introduce a breaking change using it with better-call but will be a good thing to have. will check on this.
Author
Owner

@Bekacru commented on GitHub (Nov 24, 2025):

This will require a lot of work for little gain. I think boolean is optimal enough in this case :)

<!-- gh-comment-id:3568491416 --> @Bekacru commented on GitHub (Nov 24, 2025): This will require a lot of work for little gain. I think boolean is optimal enough in this case :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27177