// 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>()],
});
// 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>()],
});