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

@ -19,6 +19,7 @@ import { Trans, useTranslation } from "react-i18next";
import { Form, Button, Alert } from "react-bootstrap";
import ErrorAlert from "~/components/ErrorAlert";
import i18n from "~/i18next.server";
import { tokenCookieName } from "~/lib/utils";
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return [{ title: `${data?.meta.title || "Log in"} • pronouns.cc` }];
@ -53,7 +54,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
},
{
headers: {
"Set-Cookie": writeCookie("pronounscc-token", resp.token!),
"Set-Cookie": writeCookie(tokenCookieName, resp.token!),
},
},
);
@ -90,7 +91,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
return redirect("/auth/welcome", {
headers: {
"Set-Cookie": writeCookie("pronounscc-token", resp.token),
"Set-Cookie": writeCookie(tokenCookieName, resp.token),
},
status: 303,
});

View file

@ -19,6 +19,7 @@ import { AuthResponse, AuthUrls } from "~/lib/api/auth";
import { ApiError, ErrorCode } from "~/lib/api/error";
import ErrorAlert from "~/components/ErrorAlert";
import { User } from "~/lib/api/user";
import { tokenCookieName } from "~/lib/utils";
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return [{ title: `${data?.meta.title || "Log in"} • pronouns.cc` }];
@ -61,7 +62,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
return redirect("/", {
status: 303,
headers: {
"Set-Cookie": writeCookie("pronounscc-token", resp.token),
"Set-Cookie": writeCookie(tokenCookieName, resp.token),
},
});
} catch (e) {

View file

@ -1,10 +1,11 @@
import { ActionFunction } from "@remix-run/node";
import { writeCookie } from "~/lib/request.server";
import { tokenCookieName } from "~/lib/utils";
export const action: ActionFunction = async () => {
return new Response(null, {
headers: {
"Set-Cookie": writeCookie("pronounscc-token", "token", 0),
"Set-Cookie": writeCookie(tokenCookieName, "token", 0),
},
status: 204,
});

View file

@ -1,6 +1,6 @@
import { ActionFunction } from "@remix-run/node";
import { UserSettings } from "~/lib/api/user";
import serverRequest, { getCookie, writeCookie } from "~/lib/request.server";
import serverRequest, { getToken, writeCookie } from "~/lib/request.server";
// Handles theme switching
// Remix itself handles redirecting back to the original page after the setting is set
@ -15,7 +15,7 @@ export const action: ActionFunction = async ({ request }) => {
const body = await request.formData();
const theme = (body.get("theme") as string | null) || "auto";
const token = getCookie(request, "pronounscc-token");
const token = getToken(request);
if (token) {
await serverRequest<UserSettings>("PATCH", "/users/@me/settings", {
token,