Updates
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
import encrypt from "../../../functions/dsql/encrypt";
|
||||
import apiGoogleLogin from "../../../functions/api/users/social/api-google-login";
|
||||
import getAuthCookieNames from "../../../functions/backend/cookies/get-auth-cookie-names";
|
||||
import { writeAuthFile } from "../../../functions/backend/auth/write-auth-files";
|
||||
import {
|
||||
APIGoogleLoginFunctionParams,
|
||||
APIResponseObject,
|
||||
GoogleAuthParams,
|
||||
} from "../../../types";
|
||||
import grabCookieExpiryDate from "../../../utils/grab-cookie-expirt-date";
|
||||
import queryDSQLAPI from "../../../functions/api/query-dsql-api";
|
||||
import grabUserDSQLAPIPath from "../../../utils/backend/users/grab-api-path";
|
||||
import postLoginResponseHandler from "../../../functions/backend/auth/post-login-response-handler";
|
||||
|
||||
/**
|
||||
* # SERVER FUNCTION: Login with google Function
|
||||
@@ -29,9 +26,9 @@ export default async function googleAuth({
|
||||
loginOnly,
|
||||
useLocal,
|
||||
apiVersion,
|
||||
skipWriteAuthFile,
|
||||
cleanupTokens,
|
||||
}: GoogleAuthParams): Promise<APIResponseObject> {
|
||||
const COOKIE_EXPIRY_DATE = grabCookieExpiryDate();
|
||||
|
||||
const finalEncryptionKey =
|
||||
encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
||||
const finalEncryptionSalt =
|
||||
@@ -111,36 +108,18 @@ export default async function googleAuth({
|
||||
*
|
||||
* @description make a request to datasquirel.com
|
||||
*/
|
||||
if (httpResponse?.success && httpResponse?.payload) {
|
||||
let encryptedPayload = encrypt({
|
||||
data: JSON.stringify(httpResponse.payload),
|
||||
encryptionKey: finalEncryptionKey,
|
||||
encryptionSalt: finalEncryptionSalt,
|
||||
});
|
||||
|
||||
const cookieNames = getAuthCookieNames({
|
||||
if (httpResponse?.success && httpResponse?.payload && database) {
|
||||
postLoginResponseHandler({
|
||||
database,
|
||||
httpResponse,
|
||||
cleanupTokens,
|
||||
debug,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
response,
|
||||
secureCookie,
|
||||
skipWriteAuthFile,
|
||||
});
|
||||
|
||||
if (httpResponse.csrf) {
|
||||
writeAuthFile(
|
||||
httpResponse.csrf,
|
||||
JSON.stringify(httpResponse.payload)
|
||||
);
|
||||
}
|
||||
|
||||
httpResponse["cookieNames"] = cookieNames;
|
||||
httpResponse["key"] = String(encryptedPayload);
|
||||
|
||||
const authKeyName = cookieNames.keyCookieName;
|
||||
const csrfName = cookieNames.csrfCookieName;
|
||||
|
||||
response?.setHeader("Set-Cookie", [
|
||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;;Expires=${COOKIE_EXPIRY_DATE}${
|
||||
secureCookie ? ";Secure=true" : ""
|
||||
}`,
|
||||
`${csrfName}=${httpResponse.payload?.csrf_k};samesite=strict;path=/;HttpOnly=true;;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
]);
|
||||
}
|
||||
|
||||
return httpResponse;
|
||||
|
||||
Reference in New Issue
Block a user