Better AuthBA
Better Auth•10mo ago
vz

Global onSuccess Hook does not work in auth-client

I am setting up bearer token following https://www.better-auth.com/docs/plugins/bearer

My code:
import { env } from "@/env";
import { createAuthClient } from "better-auth/react";
import { magicLinkClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({
    baseURL: env.NEXT_PUBLIC_BETTER_AUTH_URL,
    plugins: [magicLinkClient()],
    fetchOptions: {
        onSuccess: (ctx) => {
            console.debug("Auth client response headers", ctx.response.headers);
            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) {
                console.debug("🔑 Auth Token Set", authToken);
                localStorage.setItem("bearer_token", authToken);
            }
        },
    },
});
export const { signIn, signUp, useSession, signOut, magicLink } = authClient;


i dont see Auth client response headers in the logs
Authenticate API requests using Bearer tokens instead of browser cookies
Was this page helpful?