vz
BABetter Auth
•Created by vz on 3/2/2025 in #help
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:
i dont see
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;
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;
Auth client response headers
in the logs1 replies