diff --git a/core/components/AdminVault/index.js b/core/components/AdminVault/index.js index 6142dfe76..247da03b0 100644 --- a/core/components/AdminVault/index.js +++ b/core/components/AdminVault/index.js @@ -100,7 +100,6 @@ export default class AdminVault { } - //================================================================ /** * sets the admins file refresh routine */ @@ -111,7 +110,6 @@ export default class AdminVault { } - //================================================================ /** * Creates a admins.json file based on the first account * @param {string} username @@ -159,7 +157,6 @@ export default class AdminVault { } - //================================================================ /** * Returns a list of admins and permissions */ @@ -176,7 +173,6 @@ export default class AdminVault { } - //================================================================ /** * Returns the raw array of admins, except for the hash */ @@ -186,7 +182,6 @@ export default class AdminVault { } - //================================================================ /** * Returns all data from an admin by provider user id (ex discord id), or false * @param {string} uid @@ -204,7 +199,6 @@ export default class AdminVault { } - //================================================================ /** * Returns all data from an admin by their name, or false * @param {string} uname @@ -220,7 +214,6 @@ export default class AdminVault { } - //================================================================ /** * Returns all data from an admin by game identifier, or false * @param {string[]} identifiers @@ -239,7 +232,6 @@ export default class AdminVault { } - //================================================================ /** * Returns a list with all registered permissions */ @@ -248,7 +240,6 @@ export default class AdminVault { } - //================================================================ /** * Writes to storage the admins file */ @@ -260,7 +251,6 @@ export default class AdminVault { } - //================================================================ /** * Writes to storage the admins file */ @@ -288,7 +278,6 @@ export default class AdminVault { } - //================================================================ /** * Add a new admin to the admins file * NOTE: I'm fully aware this coud be optimized. Leaving this way to improve readability and error verbosity @@ -345,7 +334,6 @@ export default class AdminVault { } - //================================================================ /** * Edit admin and save to the admins file * @param {string} name @@ -404,7 +392,6 @@ export default class AdminVault { } - //================================================================ /** * Refreshes admin's social login data * @param {string} name @@ -437,7 +424,6 @@ export default class AdminVault { } - //================================================================ /** * Delete admin and save to the admins file * @param {string} name @@ -467,7 +453,6 @@ export default class AdminVault { } } - //================================================================ /** * Loads the admins.json file into the admins list * NOTE: The verbosity here is driving me insane. @@ -553,7 +538,6 @@ export default class AdminVault { } - //================================================================ /** * Notify game server about admin changes */ diff --git a/core/components/AdminVault/providers/CitizenFX.js b/core/components/AdminVault/providers/CitizenFX.js index bcd76fa12..187b1b6b3 100644 --- a/core/components/AdminVault/providers/CitizenFX.js +++ b/core/components/AdminVault/providers/CitizenFX.js @@ -122,12 +122,14 @@ export default class CitizenFXProvider { * * @param {object} tokenSet * @param {object} userInfo - * @returns {(object)} + * @param {string} identifier + * @returns {object} */ - async getUserSession(tokenSet, userInfo) { + async getUserSession(tokenSet, userInfo, identifier) { return { provider: 'citizenfx', provider_uid: userInfo.name, + provider_identifier: identifier, // expires_at: tokenSet.expires_at, expires_at: Math.round(Date.now() / 1000) + 86400, picture: userInfo.picture, diff --git a/core/components/WebServer/requestAuthenticator.js b/core/components/WebServer/requestAuthenticator.js index 3c54071cd..421215a81 100644 --- a/core/components/WebServer/requestAuthenticator.js +++ b/core/components/WebServer/requestAuthenticator.js @@ -160,14 +160,14 @@ export const authLogic = (sess, perm, epType) => { let admin = globals.adminVault.getAdminByName(sess.auth.username); if (admin) { if ( - typeof sess.auth.password_hash == 'string' - && admin.password_hash == sess.auth.password_hash + typeof sess.auth.password_hash === 'string' + && admin.password_hash === sess.auth.password_hash ) { isValidAuth = true; } else if ( - typeof sess.auth.provider == 'string' - && typeof admin.providers[sess.auth.provider] == 'object' - && sess.auth.provider_uid == admin.providers[sess.auth.provider].id + typeof sess.auth.provider === 'string' + && typeof admin.providers[sess.auth.provider] === 'object' + && sess.auth.provider_identifier === admin.providers[sess.auth.provider].identifier ) { isValidAuth = true; } diff --git a/core/webroutes/authentication/providerCallback.js b/core/webroutes/authentication/providerCallback.js index 2bd929a95..1151ff899 100644 --- a/core/webroutes/authentication/providerCallback.js +++ b/core/webroutes/authentication/providerCallback.js @@ -1,6 +1,6 @@ const modulename = 'WebServer:ProviderCallback'; import crypto from 'node:crypto'; -import logger from '@core/extras/console.js'; +import logger, { ogConsole } from '@core/extras/console.js'; import { verbose } from '@core/globalData'; const { dir, log, logOk, logWarn, logError } = logger(modulename); @@ -102,7 +102,7 @@ export default async function ProviderCallback(ctx) { //Check & Login user try { - const admin = globals.adminVault.getAdminByProviderUID(userInfo.name); + const admin = globals.adminVault.getAdminByIdentifiers([identifier]); if (!admin) { ctx.session.auth = {}; return returnJustMessage( @@ -113,7 +113,7 @@ export default async function ProviderCallback(ctx) { } //Setting session - ctx.session.auth = await globals.adminVault.providers.citizenfx.getUserSession(tokenSet, userInfo); + ctx.session.auth = await globals.adminVault.providers.citizenfx.getUserSession(tokenSet, userInfo, identifier); ctx.session.auth.username = admin.name; //Save the updated provider identifier & data to the admins file diff --git a/docs/dev_notes.md b/docs/dev_notes.md index 01dbb908f..aae20115d 100644 --- a/docs/dev_notes.md +++ b/docs/dev_notes.md @@ -31,7 +31,7 @@ - [x] set nui/vite.config.ts > target > chrome103 - [x] checkJoin: add messages to locale files - [x] checkJoin: customMessage `\n` to `
` -- [ ] fix cfx.re login match by admin id +- [x] fix(core): cfx.re login match by admin id instead of name - [ ] bot: change settings page description - [ ] update readme with new features - [ ] fix broken runtime stats