Fix bearer cookie being base64ed

This commit is contained in:
Zoe Roux 2025-11-03 12:39:27 +01:00
parent 572ddc69ad
commit bc6c93c9c7
No known key found for this signature in database
2 changed files with 9 additions and 3 deletions

View File

@ -10,7 +10,7 @@ const writeAccounts = (accounts: Account[]) => {
if (!selected) return;
setCookie("account", selected);
// cookie used for images and videos since we can't add Authorization headers in img or video tags.
setCookie("X-Bearer", selected?.token);
setCookie("X-Bearer", selected?.token, { skipBase64: true });
}
};

View File

@ -15,8 +15,14 @@ function fromBase64(b64: string) {
return Buffer.from(b64, "base64").toString("utf8");
}
export const setCookie = (key: string, val?: unknown) => {
const value = toBase64(typeof val !== "string" ? JSON.stringify(val) : val);
export const setCookie = (
key: string,
val?: unknown,
opts?: { skipBase64?: boolean },
) => {
const value = opts?.skipBase64
? val
: toBase64(typeof val !== "string" ? JSON.stringify(val) : val);
const d = new Date();
// A year
d.setTime(d.getTime() + 365 * 24 * 60 * 60 * 1000);