[web app Client Code]
async function verify(idToken) {
const url = "<cloud func>";
const option = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: 'include',
body: JSON.stringify({
idToken: idToken,
}),
};
const response = await fetch(url, option);
const data = await response.json();
}
[Cloud func Code]
exports.verifyIdToken = onRequest(
{
cors: "<client domain>",
},
async (req, res) => {
try {
const idToken = req.body.idToken;
const tokenPayload = await verifyJWT(idToken);
res.set({
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Origin": "<client domain>",
});
res.cookie("Cookie_Name", "values", {
maxAge: 3600,
httpOnly: true,
secure: true,
sameSite: "none",
path: "<client domain>",
});
res.json({ result: "success" });
} catch (error) {
logger.error("JWT failed:", error.message);
if (error.message == "jwt expired") {
res.json({ result: "expired" });
} else {
res.json({ result: error.message });
}
}
}
);
I set it as above, but I get an error.
"The value of the 'Access-Control-Allow-Credentials' header in the response is '' which must be 'true' when the request's credentials mode is 'include'."
I'd like to know what could be the reason.
The point of my question is, "Access-Control-Allow-Credentials": true Doing this will result in the same error as above.
I get a 204 response from preflight and this request throws an error.
When using "express" it works fine.