This commit is contained in:
Benjamin Toby
2025-03-17 08:48:58 +01:00
parent ec4d0428bb
commit 34f843bc84
20 changed files with 113 additions and 46 deletions
@@ -31,6 +31,7 @@ type Param = {
additionalFields?: string[];
additionalData?: { [s: string]: string | number };
user_id?: boolean;
secureCookie?: boolean;
};
/**
@@ -49,6 +50,7 @@ export default async function githubAuth({
additionalFields,
user_id,
additionalData,
secureCookie,
}: Param): Promise<FunctionReturn | undefined> {
/**
* Check inputs
@@ -228,10 +230,10 @@ export default async function githubAuth({
const csrfName = `datasquirel_${dsqlUserId}_${database}_csrf`;
response.setHeader("Set-Cookie", [
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true${
secureCookie ? ";Secure=true" : ""
}`,
`${csrfName}=${user.csrf_k};samesite=strict;path=/;HttpOnly=true`,
`dsqluid=${dsqlUserId};samesite=strict;path=/;HttpOnly=true`,
`datasquirel_social_id=${user.social_id};samesite=strict;path=/`,
]);
}
@@ -17,6 +17,7 @@ type Param = {
additionalData?: { [s: string]: string | number };
apiUserID?: string | number;
debug?: boolean;
secureCookie?: boolean;
};
/**
@@ -33,6 +34,7 @@ export default async function googleAuth({
additionalData,
apiUserID,
debug,
secureCookie,
}: Param): Promise<APILoginFunctionReturn> {
const grabedHostNames = grabHostNames({
userId: apiUserID || process.env.DSQL_API_USER_ID,
@@ -192,7 +194,9 @@ export default async function googleAuth({
const csrfName = cookieNames.csrfCookieName;
response?.setHeader("Set-Cookie", [
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true${
secureCookie ? ";Secure=true" : ""
}`,
`${csrfName}=${httpResponse.payload?.csrf_k};samesite=strict;path=/;HttpOnly=true`,
]);
}