Fix secure cookies bug
This commit is contained in:
@@ -15,10 +15,13 @@ import grabMediaURL from "../media/grab-media-url";
|
|||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
user_id: string | number;
|
user_id: string | number;
|
||||||
|
/** Set the Secure attribute only when served over HTTPS */
|
||||||
|
secure?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function loginUser({
|
export default async function loginUser({
|
||||||
user_id,
|
user_id,
|
||||||
|
secure,
|
||||||
}: Params): Promise<Response> {
|
}: Params): Promise<Response> {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
@@ -103,11 +106,13 @@ export default async function loginUser({
|
|||||||
name: AppData["AuthKeyCookieName"],
|
name: AppData["AuthKeyCookieName"],
|
||||||
value: encrypted_key,
|
value: encrypted_key,
|
||||||
maxAge,
|
maxAge,
|
||||||
|
secure: secure ?? false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: AppData["AuthCSRFCookieName"],
|
name: AppData["AuthCSRFCookieName"],
|
||||||
value: csrf_key,
|
value: csrf_key,
|
||||||
maxAge,
|
maxAge,
|
||||||
|
secure: secure ?? false,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async (
|
|||||||
if (reauth) {
|
if (reauth) {
|
||||||
return await loginUser({
|
return await loginUser({
|
||||||
user_id: Number(user_id),
|
user_id: Number(user_id),
|
||||||
|
secure:
|
||||||
|
req.headers.get("x-forwarded-proto") === "https" ||
|
||||||
|
req.url.startsWith("https:"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import type {
|
|||||||
|
|
||||||
export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
|
export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
|
||||||
body,
|
body,
|
||||||
|
req,
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const { login } = body as ApiReqParams;
|
const { login } = body as ApiReqParams;
|
||||||
@@ -65,6 +66,9 @@ export const handler: BunextAPIRouteHandler<APIResponseObject> = async ({
|
|||||||
|
|
||||||
return await loginUser({
|
return await loginUser({
|
||||||
user_id: target_user.id,
|
user_id: target_user.id,
|
||||||
|
secure:
|
||||||
|
req.headers.get("x-forwarded-proto") === "https" ||
|
||||||
|
req.url.startsWith("https:"),
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user