Updates
This commit is contained in:
@@ -30,10 +30,7 @@ type Param<T = { [k: string]: any }> = {
|
||||
/**
|
||||
* # Query DSQL API
|
||||
*/
|
||||
export default async function queryDSQLAPI<
|
||||
T = { [k: string]: any },
|
||||
P = { [k: string]: any }
|
||||
>({
|
||||
export default async function queryDSQLAPI<T = { [k: string]: any }>({
|
||||
body,
|
||||
query,
|
||||
useDefault,
|
||||
@@ -42,7 +39,7 @@ export default async function queryDSQLAPI<
|
||||
apiKey,
|
||||
apiConnectionConfig,
|
||||
grabbedHostnames,
|
||||
}: Param<T>): Promise<APIResponseObject<P>> {
|
||||
}: Param<T>): Promise<APIResponseObject> {
|
||||
const grabedHostNames =
|
||||
grabbedHostnames || grabHostNames({ useDefault, apiConnectionConfig });
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
@@ -168,7 +165,7 @@ export default async function queryDSQLAPI<
|
||||
httpsRequest.end();
|
||||
});
|
||||
|
||||
return httpResponse as APIResponseObject<P>;
|
||||
return httpResponse as APIResponseObject;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -152,8 +152,8 @@ export default async function handleSocialDb({
|
||||
},
|
||||
});
|
||||
|
||||
if (newUser?.payload?.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.payload.insertId}'`;
|
||||
if (newUser?.postInsertReturn?.insertId) {
|
||||
const newUserQueriedQuery = `SELECT * FROM users WHERE id='${newUser.postInsertReturn.insertId}'`;
|
||||
|
||||
const newUserQueried = (await dbHandler({
|
||||
database: finalDbName,
|
||||
@@ -175,7 +175,7 @@ export default async function handleSocialDb({
|
||||
*/
|
||||
let generatedToken = encrypt({
|
||||
data: JSON.stringify({
|
||||
id: newUser.payload.insertId,
|
||||
id: newUser.postInsertReturn.insertId,
|
||||
email: supEmail,
|
||||
dateCode: Date.now(),
|
||||
}),
|
||||
|
||||
@@ -163,8 +163,8 @@ export default async function apiCreateUser({
|
||||
},
|
||||
});
|
||||
|
||||
if (addUser?.payload?.insertId) {
|
||||
const newlyAddedUserQuery = `SELECT id,uuid,first_name,last_name,email,username,image,image_thumbnail,verification_status FROM ${dbFullName}.users WHERE id='${addUser.payload.insertId}'`;
|
||||
if (addUser?.postInsertReturn?.insertId) {
|
||||
const newlyAddedUserQuery = `SELECT id,uuid,first_name,last_name,email,username,image,image_thumbnail,verification_status FROM ${dbFullName}.users WHERE id='${addUser.postInsertReturn.insertId}'`;
|
||||
|
||||
const newlyAddedUser = (await dbHandler({
|
||||
query: newlyAddedUserQuery,
|
||||
|
||||
@@ -184,7 +184,7 @@ export default async function apiLoginUser({
|
||||
const resposeObject: APIResponseObject = {
|
||||
success: true,
|
||||
msg: "Login Successful",
|
||||
payload: userPayload,
|
||||
singleRes: userPayload,
|
||||
userId: foundUser[0].id,
|
||||
csrf: csrfKey,
|
||||
};
|
||||
|
||||
@@ -48,6 +48,6 @@ export default async function apiResetUserPassword({
|
||||
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -81,6 +81,6 @@ export default async function apiUpdateUser({
|
||||
|
||||
return {
|
||||
success: true,
|
||||
payload: updateUser,
|
||||
singleRes: updateUser,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import handleSocialDb from "../../social-login/handleSocialDb";
|
||||
import githubLogin from "../../social-login/githubLogin";
|
||||
import camelJoinedtoCamelSpace from "../../../../utils/camelJoinedtoCamelSpace";
|
||||
import { APILoginFunctionReturn } from "../../../../types";
|
||||
import { APILoginFunctionReturn, APIResponseObject } from "../../../../types";
|
||||
|
||||
type Param = {
|
||||
code?: string;
|
||||
@@ -24,7 +24,7 @@ export default async function apiGithubLogin({
|
||||
additionalFields,
|
||||
email,
|
||||
additionalData,
|
||||
}: Param): Promise<APILoginFunctionReturn> {
|
||||
}: Param): Promise<APIResponseObject> {
|
||||
if (!code || !clientId || !clientSecret || !database) {
|
||||
return {
|
||||
success: false,
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function postLoginResponseHandler({
|
||||
|
||||
if (httpResponse?.success) {
|
||||
let encryptedPayload = encrypt({
|
||||
data: JSON.stringify(httpResponse.payload),
|
||||
data: JSON.stringify(httpResponse.singleRes),
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
@@ -61,9 +61,9 @@ export default function postLoginResponseHandler({
|
||||
if (httpResponse.csrf && !skipWriteAuthFile) {
|
||||
writeAuthFile(
|
||||
httpResponse.csrf,
|
||||
JSON.stringify(httpResponse.payload),
|
||||
cleanupTokens && httpResponse.payload?.id
|
||||
? { userId: httpResponse.payload.id }
|
||||
JSON.stringify(httpResponse.singleRes),
|
||||
cleanupTokens && httpResponse.singleRes?.id
|
||||
? { userId: httpResponse.singleRes.id }
|
||||
: undefined
|
||||
);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ export default function postLoginResponseHandler({
|
||||
`${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}`,
|
||||
`${csrfName}=${httpResponse.singleRes?.csrf_k};samesite=strict;path=/;HttpOnly=true;Expires=${COOKIE_EXPIRY_DATE}`,
|
||||
]);
|
||||
|
||||
if (debug) {
|
||||
|
||||
@@ -43,7 +43,7 @@ export default async function suAddBackup({
|
||||
data: newBackup,
|
||||
});
|
||||
|
||||
if (!newBackupEntry?.payload?.insertId) {
|
||||
if (!newBackupEntry?.postInsertReturn?.insertId) {
|
||||
return {
|
||||
success: false,
|
||||
msg: `Couldn't create new backup entry`,
|
||||
@@ -53,7 +53,7 @@ export default async function suAddBackup({
|
||||
const { single: newlyAddedBackup } =
|
||||
await dbGrabUserResource<DSQL_DATASQUIREL_BACKUPS>({
|
||||
tableName: "backups",
|
||||
targetID: newBackupEntry.payload?.insertId,
|
||||
targetID: newBackupEntry.postInsertReturn?.insertId,
|
||||
isSuperUser: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ export default async function deleteDbEntry<
|
||||
*/
|
||||
return {
|
||||
success: Boolean(deletedEntry.affectedRows),
|
||||
payload: deletedEntry,
|
||||
postInsertReturn: deletedEntry,
|
||||
queryObject: {
|
||||
sql: format(query),
|
||||
params: values,
|
||||
|
||||
@@ -161,7 +161,7 @@ export default async function updateDbEntry<
|
||||
*/
|
||||
return {
|
||||
success: Boolean(updatedEntry?.affectedRows),
|
||||
payload: updatedEntry,
|
||||
postInsertReturn: updatedEntry,
|
||||
queryObject: {
|
||||
sql: format(query),
|
||||
params: updateValues,
|
||||
|
||||
@@ -78,7 +78,9 @@ export default async function handleMariadbUserRecord({
|
||||
query: {
|
||||
id: {
|
||||
value: String(
|
||||
existingRecord?.id || record?.payload?.insertId || 0
|
||||
existingRecord?.id ||
|
||||
record?.postInsertReturn?.insertId ||
|
||||
0
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user