send additional headers

is there a way to pass additional headers? Doing it like this throws an error and seems to completely override headers:
//client
await authClient.forgetPassword({
email: value.email,
redirectTo: window.location.origin + "/reset-password",
fetchOptions: {
headers: {
"new-header": "new-value",
},
},
});

//server
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
sendResetPassword: async (data, request) => {
console.log("headers", request.headers)
},
},
//client
await authClient.forgetPassword({
email: value.email,
redirectTo: window.location.origin + "/reset-password",
fetchOptions: {
headers: {
"new-header": "new-value",
},
},
});

//server
export const auth = betterAuth({
emailAndPassword: {
enabled: true,
sendResetPassword: async (data, request) => {
console.log("headers", request.headers)
},
},
8 Replies
Ping
Ping2w ago
Just get the existing headers and append your new ones.
h3llo
h3lloOP2w ago
how do you get the existing headers with authclient in browser? i dont have the callback function for headers (or for fetch options)
Ping
Ping2w ago
Actually all you need is cookies, but I just realized that I'm not sure you can do this on prod when cookies are stored with secure So ignore me, I'm wrong 😁
h3llo
h3lloOP2w ago
ah ok should i ping bekacru if you aren't aware of ways to pass additional headers?
Ping
Ping2w ago
Can you try passing query params maybe?
h3llo
h3lloOP2w ago
yeah, they get attached so there's no way to attach additional headers/cookies from the client?
Ping
Ping2w ago
Probably not, but it's possible I'm wrong.
h3llo
h3lloOP2w ago
@bekacru do you maybe know if there's a way to do it?

Did you find this page helpful?