Credentials not included when making a server side request
Unanswered
Asiatic Lion posted this in #help-forum
Asiatic LionOP
Hi, I'm using AuthJS for authentication. I'm trying to make an update profile form to take in some updated user info and update the form. I already have handled the login and the cookies needed for my django backend to authenticate are present.
the
The main issue is that I receive a 401 response from my server indicating that the credentials have not been passed sent in the request or accepted by the server.
There are a couple of problems which make this issue harder to debug:
1. The server side request is not logged in chrome dev tools, only the client side request that calls the server action is logged, which makes it impossible to see what was actually sent in the request.
2. My backend server is on https and my frontend is http. I use
function onSubmit(data: z.infer<typeof UpdateUserFormSchema>) {
const modifiedData = dgfdg;
return new Promise(async (resolve) => {
await update(modifiedData).catch((error) => {
if (error.message) {
console.error("Failed to parse JSON error:", jsonError);
form.setError("root", {
type: "custom",
message: "An unexpected error occurred.",
});
}
});
resolve(true);
});
}the
update function is a server action that looks like so:export const update = async (data: z.infer<typeof UpdateUserFormSchema>) => {
const res = axios
.post(`${process.env.BACKEND_URL}/accounts/update/`, formData, {
headers,
withCredentials: true, // This is equivalent to credentials: "include" in fetch
})
.then((res) => {
console.log("cookies: ", cookieStore.getAll());
console.log("res: ", res.data());
})
.catch((error) => {
console.log("errored");
throw new Error(error);
});
};The main issue is that I receive a 401 response from my server indicating that the credentials have not been passed sent in the request or accepted by the server.
There are a couple of problems which make this issue harder to debug:
1. The server side request is not logged in chrome dev tools, only the client side request that calls the server action is logged, which makes it impossible to see what was actually sent in the request.
2. My backend server is on https and my frontend is http. I use
NODE_TLS_REJECT_UNAUTHORIZED='0' env variable to overcome this issue, not sure if this impacts the ability to send cookies.