This commit is contained in:
2026-03-09 16:49:49 +00:00
parent 8491c52639
commit 76bf623116
27 changed files with 460 additions and 46 deletions
+2 -8
View File
@@ -49,14 +49,8 @@ export function setCookie(
res.setHeader("Set-Cookie", final_cookie_string);
}
export function getCookie(
req: http.IncomingMessage,
name: string,
): string | null {
const cookieHeader = req.headers.cookie;
if (!cookieHeader) return null;
const cookies = cookieHeader
export function getCookie(cookie_string: string, name: string): string | null {
const cookies = cookie_string
.split(";")
.reduce((acc: { [key: string]: string }, cookie: string) => {
const [key, val] = cookie.trim().split("=").map(decodeURIComponent);
+14 -3
View File
@@ -8,17 +8,28 @@ import { EJSON } from "../exports/client-exports";
import grabCookieNames from "./grab-cookie-names";
type Params = {
req:
req?:
| NextApiRequest
| (IncomingMessage & { cookies: Partial<{ [key: string]: string }> });
bun_req?: Request;
};
export default async function userAuth({
req,
bun_req,
}: Params): Promise<APIResponseObject<User>> {
try {
const { auth_key_cookie_name, csrf_cookie_name } = grabCookieNames();
const key = getCookie(req, auth_key_cookie_name);
const cookie_string =
req?.headers.cookie || bun_req?.headers.get("cookie");
if (!cookie_string) {
return {
success: false,
msg: `Couldn't grab cookie string`,
};
}
const key = getCookie(cookie_string, auth_key_cookie_name);
if (!key) {
return {
@@ -37,7 +48,7 @@ export default async function userAuth({
};
}
const csrf = getCookie(req, csrf_cookie_name);
const csrf = getCookie(cookie_string, csrf_cookie_name);
if (!csrf) {
return {