[GH-ISSUE #702] useSession not working when using throw fetch options #8386

Closed
opened 2026-04-13 03:27:41 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @nayzflux on GitHub (Nov 29, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/702

Describe the bug
When i choose throw to true in fetch options when i instantiate a new auth client the useSession function returned values changes. I think the error is only a typescript error as i am able to use the useSession hooks even when getting a type error

To Reproduce
Steps to reproduce the behavior:

  1. Create a new Auth Client
  2. Set fetch options throw to true
  3. Watch returned type of useSession hooks
  4. Log the session
  5. See the wrong type

Expected behavior
The useSession should return the same value even when using throw option to true

Screenshots
Capture d'écran 2024-11-29 195954
Capture d'écran 2024-11-29 195946
Capture d'écran 2024-11-29 200340

Desktop (please complete the following information):

  • OS: Windows 11 - WSL Ubuntu
  • Browser: Firefox

Buggy

import { env } from "@/lib/env";
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
  baseURL: env.NEXT_PUBLIC_API_URL,
  fetchOptions: {
    throw: true,
  },
});

Not buggy

import { env } from "@/lib/env";
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
  baseURL: env.NEXT_PUBLIC_API_URL,
  fetchOptions: {
    //throw: true,
  },
});
Originally created by @nayzflux on GitHub (Nov 29, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/702 **Describe the bug** When i choose throw to true in fetch options when i instantiate a new auth client the useSession function returned values changes. I think the error is only a typescript error as i am able to use the useSession hooks even when getting a type error **To Reproduce** Steps to reproduce the behavior: 1. Create a new Auth Client 2. Set fetch options throw to true 3. Watch returned type of useSession hooks 4. Log the session 5. See the wrong type **Expected behavior** The useSession should return the same value even when using throw option to true **Screenshots** ![Capture d'écran 2024-11-29 195954](https://github.com/user-attachments/assets/29ef6942-eca5-4fae-8a44-a5cf34b299ed) ![Capture d'écran 2024-11-29 195946](https://github.com/user-attachments/assets/cf6d3376-e9e0-49da-b7b8-2bbec3e8e464) ![Capture d'écran 2024-11-29 200340](https://github.com/user-attachments/assets/aa89ab39-11fd-443a-a45e-5d3348cbe569) **Desktop (please complete the following information):** - OS: Windows 11 - WSL Ubuntu - Browser: Firefox Buggy ```ts import { env } from "@/lib/env"; import { createAuthClient } from "better-auth/react"; export const authClient = createAuthClient({ baseURL: env.NEXT_PUBLIC_API_URL, fetchOptions: { throw: true, }, }); ``` Not buggy ```ts import { env } from "@/lib/env"; import { createAuthClient } from "better-auth/react"; export const authClient = createAuthClient({ baseURL: env.NEXT_PUBLIC_API_URL, fetchOptions: { //throw: true, }, }); ```
GiteaMirror added the locked label 2026-04-13 03:27:41 -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#8386