Skip to content

Commit 6a591e0

Browse files
committed
feat(core): added details to "changing own ids" action log msg
Example log output: [06:37:56][tabby] logged in from 127.0.0.1 via password auth [06:38:05][tabby] Modified own identifiers: removed fivem:271816, removed discord:272800190639898628 [06:38:11][tabby] Modified own identifiers: added fivem:1427561 [06:38:19][tabby] Modified own identifiers: changed fivem:1427561 → fivem:271816 [06:38:24][tabby] Modified own identifiers: added discord:272800190639898628 Note: Also improved the login log action entries for better auditing.
1 parent e2a5c92 commit 6a591e0

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

core/routes/authentication/changeIdentifiers.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,41 @@ export default async function AuthChangeIdentifiers(ctx: AuthedCtx) {
7878
const vaultAdmin = txCore.adminStore.getAdminByName(ctx.admin.name);
7979
if (!vaultAdmin) throw new Error('Wait, what? Where is that admin?');
8080

81+
//Prepare log message
82+
const changes: string[] = [];
83+
const oldCfx = vaultAdmin.providers.citizenfx?.identifier;
84+
const newCfx = citizenfxData ? citizenfxData.identifier : undefined;
85+
if (oldCfx !== newCfx) {
86+
if (!oldCfx && newCfx) {
87+
changes.push(`added ${newCfx}`);
88+
} else if (oldCfx && !newCfx) {
89+
changes.push(`removed ${oldCfx}`);
90+
} else if (oldCfx && newCfx) {
91+
changes.push(`changed ${oldCfx}${newCfx}`);
92+
}
93+
}
94+
95+
const oldDiscord = vaultAdmin.providers.discord?.identifier;
96+
const newDiscord = discordData ? discordData.identifier : undefined;
97+
if (oldDiscord !== newDiscord) {
98+
if (!oldDiscord && newDiscord) {
99+
changes.push(`added ${newDiscord}`);
100+
} else if (oldDiscord && !newDiscord) {
101+
changes.push(`removed ${oldDiscord}`);
102+
} else if (oldDiscord && newDiscord) {
103+
changes.push(`changed ${oldDiscord}${newDiscord}`);
104+
}
105+
}
106+
107+
const logMessage = changes.length
108+
? `Modified own identifiers: ${changes.join(', ')}`
109+
: 'Modified own identifiers: No changes detected.';
110+
81111
//Edit admin and give output
82112
try {
83113
await txCore.adminStore.editAdmin(ctx.admin.name, null, citizenfxData, discordData);
84114

85-
ctx.admin.logAction('Changing own identifiers.');
115+
ctx.admin.logAction(logMessage);
86116
return ctx.send<GenericApiResp>({ success: true });
87117
} catch (error) {
88118
return ctx.send<GenericApiResp>({ error: (error as Error).message });

core/routes/authentication/providerCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default async function AuthProviderCallback(ctx: InitializedCtx) {
7474
}
7575

7676
const authedAdmin = new AuthedAdmin(vaultAdmin, sessData.csrfToken);
77-
authedAdmin.logAction(`logged in from ${ctx.ip} via cfxre`);
77+
authedAdmin.logAction(`logged in from ${ctx.ip} via cfxre auth`);
7878
txCore.metrics.txRuntime.loginOrigins.count(ctx.txVars.hostType);
7979
txCore.metrics.txRuntime.loginMethods.count('citizenfx');
8080
return ctx.send<ReactAuthDataType>(authedAdmin.getAuthData());

core/routes/authentication/verifyPassword.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ export default async function AuthVerifyPassword(ctx: InitializedCtx) {
6868
} satisfies PassSessAuthType;
6969
ctx.sessTools.set({ auth: sessData });
7070

71-
txCore.logger.admin.write(vaultAdmin.name, `logged in from ${ctx.ip} via password`);
71+
const authedAdmin = new AuthedAdmin(vaultAdmin, sessData.csrfToken);
72+
authedAdmin.logAction(`logged in from ${ctx.ip} via password auth`);
7273
txCore.metrics.txRuntime.loginOrigins.count(ctx.txVars.hostType);
7374
txCore.metrics.txRuntime.loginMethods.count('password');
74-
75-
const authedAdmin = new AuthedAdmin(vaultAdmin, sessData.csrfToken)
7675
return ctx.send<ReactAuthDataType>(authedAdmin.getAuthData());
77-
7876
} catch (error) {
7977
console.warn(`Failed to authenticate ${postBody.username} with error: ${(error as Error).message}`);
8078
console.verbose.dir(error);

0 commit comments

Comments
 (0)