This commit is contained in:
Benjamin Toby 2024-12-28 08:03:57 +01:00
parent d2ff524d86
commit e7fafc1bb6
10 changed files with 41 additions and 46 deletions

View File

@ -1,11 +1,12 @@
declare function _exports({ code, clientId, clientSecret, database, additionalFields, res, email, userId, }: {
declare function _exports({ code, clientId, clientSecret, database, additionalFields, email, additionalData, }: {
code?: string;
clientId?: string;
clientSecret?: string;
database?: string;
additionalFields?: string[];
res?: any;
additionalData?: {
[x: string]: string | number;
};
email?: string;
userId?: string | number;
}): Promise<import("../../../../types").APILoginFunctionReturn>;
export = _exports;

View File

@ -12,9 +12,8 @@ const camelJoinedtoCamelSpace = require("../../../../utils/camelJoinedtoCamelSpa
* @param {string} [param.clientSecret]
* @param {string} [param.database]
* @param {string[]} [param.additionalFields]
* @param {any} [param.res]
* @param {Object<string,string|number>} [param.additionalData]
* @param {string} [param.email]
* @param {string | number} [param.userId]
*
* @returns {Promise<import("../../../../types").APILoginFunctionReturn>}
*/
@ -24,9 +23,8 @@ module.exports = async function apiGithubLogin({
clientSecret,
database,
additionalFields,
res,
email,
userId,
additionalData,
}) {
if (!code || !clientId || !clientSecret || !database) {
return {
@ -73,7 +71,7 @@ module.exports = async function apiGithubLogin({
? targetName?.split("-")
: [targetName];
const payload = {
let payload = {
email: gitHubUser.email,
first_name: camelJoinedtoCamelSpace(nameArray[0]),
last_name: camelJoinedtoCamelSpace(nameArray[1]),
@ -84,10 +82,14 @@ module.exports = async function apiGithubLogin({
username: "github-user-" + socialId,
};
if (additionalData) {
payload = { ...payload, ...additionalData };
}
const loggedInGithubUser = await handleSocialDb({
database,
email: gitHubUser.email,
payload: payload,
payload,
social_platform: "github",
social_id: socialId,
supEmail: email,

View File

@ -9,6 +9,7 @@ module.exports = async function apiGoogleLogin({
token,
database,
additionalFields,
additionalData,
}) {
try {
/** @type {import("../../../../types").GoogleOauth2User | undefined} */
@ -59,7 +60,7 @@ module.exports = async function apiGoogleLogin({
const { given_name, family_name, email, sub, picture } = gUser;
/** @type {Object<string, any>} */
const payloadObject = {
let payloadObject = {
email: email,
first_name: given_name,
last_name: family_name,
@ -70,6 +71,10 @@ module.exports = async function apiGoogleLogin({
username: `google-user-${sub}`,
};
if (additionalData) {
payloadObject = { ...payloadObject, ...additionalData };
}
const loggedInGoogleUser = await handleSocialDb({
database,
email: email || "",

View File

@ -1057,6 +1057,9 @@ export type APIGoogleLoginFunctionParams = {
token: string;
database: string;
additionalFields?: string[];
additionalData?: {
[key: string]: string | number;
};
};
export type APIGoogleLoginFunction = (params: APIGoogleLoginFunctionParams) => Promise<APILoginFunctionReturn>;
/**

View File

@ -1265,6 +1265,7 @@ export type APIGoogleLoginFunctionParams = {
token: string;
database: string;
additionalFields?: string[];
additionalData?: { [key: string]: string | number };
};
export type APIGoogleLoginFunction = (

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "3.2.2",
"version": "3.2.3",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {

View File

@ -29,11 +29,12 @@ export = githubAuth;
* @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {boolean} [params.user_id] - User ID
*
* @returns { Promise<FunctionReturn | undefined> }
*/
declare function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, }: {
declare function githubAuth({ key, code, email, database, clientId, clientSecret, response, encryptionKey, encryptionSalt, additionalFields, user_id, additionalData, }: {
key: string;
code: string;
email: string | null;
@ -44,6 +45,9 @@ declare function githubAuth({ key, code, email, database, clientId, clientSecret
encryptionKey: string;
encryptionSalt: string;
additionalFields?: string[];
additionalData?: {
[x: string]: string | number;
};
user_id?: boolean;
}): Promise<FunctionReturn | undefined>;
declare namespace githubAuth {

View File

@ -45,6 +45,7 @@ const apiGithubLogin = require("../../package-shared/functions/api/users/social/
* @param {string} params.encryptionKey - Encryption key
* @param {string} params.encryptionSalt - Encryption salt
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {boolean} [params.user_id] - User ID
*
* @returns { Promise<FunctionReturn | undefined> }
@ -61,6 +62,7 @@ async function githubAuth({
encryptionSalt,
additionalFields,
user_id,
additionalData,
}) {
/**
* Check inputs
@ -70,14 +72,6 @@ async function githubAuth({
const grabedHostNames = grabHostNames();
const { host, port, scheme } = grabedHostNames;
if (!key || key?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please enter API full access Key",
};
}
if (!code || code?.match(/ /)) {
return {
success: false,
@ -102,30 +96,6 @@ async function githubAuth({
};
}
if (!response || !response?.setHeader) {
return {
success: false,
user: null,
msg: "Please provide a valid HTTPS response object",
};
}
if (!encryptionKey || encryptionKey?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please provide a valid encryption key",
};
}
if (!encryptionSalt || encryptionSalt?.match(/ /)) {
return {
success: false,
user: null,
msg: "Please provide a valid encryption salt",
};
}
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
@ -173,8 +143,8 @@ async function githubAuth({
clientId,
clientSecret,
additionalFields,
res: response,
database: DSQL_DB_NAME,
additionalData,
});
} else {
/**
@ -191,6 +161,7 @@ async function githubAuth({
clientSecret,
database,
additionalFields,
additionalData,
});
const httpsRequest = scheme.request(

View File

@ -13,12 +13,13 @@ export = googleAuth;
* @param {string} [params.encryptionKey] - Encryption key
* @param {string} [params.encryptionSalt] - Encryption salt
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {string | number} [params.apiUserID] - API user ID
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
*
* @returns { Promise<import("../../package-shared/types").APILoginFunctionReturn> }
*/
declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, apiUserID, useLocal, }: {
declare function googleAuth({ key, token, database, response, encryptionKey, encryptionSalt, additionalFields, additionalData, apiUserID, useLocal, }: {
key?: string;
token: string;
database?: string;
@ -26,6 +27,9 @@ declare function googleAuth({ key, token, database, response, encryptionKey, enc
encryptionKey?: string;
encryptionSalt?: string;
additionalFields?: string[];
additionalData?: {
[x: string]: string | number;
};
apiUserID?: string | number;
useLocal?: boolean;
}): Promise<import("../../package-shared/types").APILoginFunctionReturn>;

View File

@ -23,6 +23,7 @@ const {
* @param {string} [params.encryptionKey] - Encryption key
* @param {string} [params.encryptionSalt] - Encryption salt
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
* @param {Object<string,string|number>} [params.additionalData] - Additional Data to by added on creation of User
* @param {string | number} [params.apiUserID] - API user ID
* @param {boolean} [params.useLocal] - Whether to use a remote database instead of API
*
@ -36,6 +37,7 @@ async function googleAuth({
encryptionKey,
encryptionSalt,
additionalFields,
additionalData,
apiUserID,
useLocal,
}) {
@ -106,6 +108,7 @@ async function googleAuth({
token,
additionalFields,
database: DSQL_DB_NAME,
additionalData,
});
} else {
/**
@ -119,6 +122,7 @@ async function googleAuth({
token,
database,
additionalFields,
additionalData,
});
const httpsRequest = scheme.request(