problem get-session return null when using bearer plugin

hi i have problem with better auth when using bearer plugin the login work and return user data but get-session return null and i found that happen only when both cookie and authorization header available in the request .so how i prevent better auth client from sending the cookie header or any fix for this?


// react auth client
import { createAuthClient } from "better-auth/react";

export const authClient = createAuthClient({
  
  fetchOptions: {
  

    onSuccess: (ctx) => {
      if (ctx.request.url.toString().endsWith("/api/auth/sign-out")) {
        localStorage.removeItem("bearer_token");
        return;
      }
      const authToken = ctx.response.headers.get("set-auth-token"); // get the token from the response headers
      // Store the token securely (e.g., in localStorage)
      if (authToken) {
        localStorage.setItem("bearer_token", authToken);
      }
    },
    auth: {
      type: "Bearer",
      token: () => localStorage.getItem("bearer_token") || "", // get the token from localStorage
    },
  },
  baseURL: import.meta.env.VITE_SERVER_URL,
  // plugins: [inferAdditionalFields<typeof auth>()],
});

 
Was this page helpful?