Bearer Token Null?
I'm getting frusturated at this point, whenever I try to get the bearer token it's returning null, but the actual service is still logging me in. This is my auth client config.
import { createAuthClient } from "better-auth/react";
import {
adminClient,
customSessionClient,
organizationClient,
} from "better-auth/client/plugins";
import { permBasedAdminClient } from "./plugins/betterAdmin/client";
import { auth } from "./auth";
// Helper function to safely access localStorage
const getLocalStorage = () => {
if (typeof window !== "undefined") {
return window.localStorage;
}
return null;
};
// Helper functions for token management
const getToken = () => {
const storage = getLocalStorage();
return storage ? storage.getItem("bearer_token") || "" : "";
};
export const authClient = createAuthClient({
baseURL: process.env.BASE_URL,
trustedOrigins: ["https://blahblah.com"],
fetchOptions: {
auth: {
type: "Bearer",
token: getToken,
},
},
plugins: [
organizationClient(),
permBasedAdminClient(),
customSessionClient<typeof auth>(),
],
});
export const { signIn, signOut, signUp, useSession } = authClient;import { createAuthClient } from "better-auth/react";
import {
adminClient,
customSessionClient,
organizationClient,
} from "better-auth/client/plugins";
import { permBasedAdminClient } from "./plugins/betterAdmin/client";
import { auth } from "./auth";
// Helper function to safely access localStorage
const getLocalStorage = () => {
if (typeof window !== "undefined") {
return window.localStorage;
}
return null;
};
// Helper functions for token management
const getToken = () => {
const storage = getLocalStorage();
return storage ? storage.getItem("bearer_token") || "" : "";
};
export const authClient = createAuthClient({
baseURL: process.env.BASE_URL,
trustedOrigins: ["https://blahblah.com"],
fetchOptions: {
auth: {
type: "Bearer",
token: getToken,
},
},
plugins: [
organizationClient(),
permBasedAdminClient(),
customSessionClient<typeof auth>(),
],
});
export const { signIn, signOut, signUp, useSession } = authClient;