feat(frontend): use __Host prefix for token cookie

This commit is contained in:
sam 2024-09-30 20:14:03 +02:00
parent 646c2694e1
commit 2b8e4c3e8d
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
8 changed files with 108 additions and 101 deletions

View file

@ -1,6 +1,7 @@
import { parse as parseCookie, serialize as serializeCookie } from "cookie";
import { API_BASE } from "~/env.server";
import { ApiError, ErrorCode } from "./api/error";
import { tokenCookieName } from "~/lib/utils";
export type RequestParams = {
token?: string;
@ -39,7 +40,7 @@ export default async function serverRequest<T>(
return (await resp.json()) as T;
}
export const getToken = (req: Request) => getCookie(req, "pronounscc-token");
export const getToken = (req: Request) => getCookie(req, tokenCookieName);
export function getCookie(req: Request, cookieName: string): string | undefined {
const header = req.headers.get("Cookie");
@ -57,4 +58,5 @@ export const writeCookie = (cookieName: string, value: string, maxAge: number |
path: "/",
sameSite: "lax",
httpOnly: true,
secure: true,
});