2024-11-05 11:12:42 +00:00
|
|
|
// @ts-check
|
|
|
|
|
2025-01-13 08:00:21 +00:00
|
|
|
import { IncomingMessage } from "http";
|
|
|
|
import parseCookies from "../../utils/backend/parseCookies";
|
|
|
|
import decrypt from "../dsql/decrypt";
|
|
|
|
import getAuthCookieNames from "./cookies/get-auth-cookie-names";
|
|
|
|
|
|
|
|
export default async function (req: IncomingMessage): Promise<{
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
authKey: string;
|
|
|
|
logged_in_status: boolean;
|
|
|
|
date: number;
|
|
|
|
} | null> {
|
2024-12-06 13:24:26 +00:00
|
|
|
const { keyCookieName, csrfCookieName } = getAuthCookieNames();
|
|
|
|
const suKeyName = `${keyCookieName}_su`;
|
|
|
|
|
2024-11-05 11:12:42 +00:00
|
|
|
const cookies = parseCookies({ request: req });
|
2024-12-06 13:24:26 +00:00
|
|
|
if (!cookies?.[suKeyName]) {
|
2024-11-05 11:12:42 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ********************* Grab the payload */
|
2024-12-06 13:24:26 +00:00
|
|
|
let userPayload = decrypt({
|
|
|
|
encryptedString: cookies[suKeyName],
|
|
|
|
});
|
2024-11-05 11:12:42 +00:00
|
|
|
|
|
|
|
/** ********************* Return if no payload */
|
|
|
|
if (!userPayload) return null;
|
|
|
|
|
|
|
|
/** ********************* Parse the payload */
|
|
|
|
let userObject = JSON.parse(userPayload);
|
|
|
|
|
|
|
|
if (userObject.password !== process.env.DSQL_USER_KEY) return null;
|
|
|
|
if (userObject.authKey !== process.env.DSQL_SPECIAL_KEY) return null;
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
/** ********************* return user object */
|
|
|
|
return userObject;
|
2025-01-13 08:00:21 +00:00
|
|
|
}
|