add client ip to signup webhook
deploy / build-and-deploy (push) Successful in 34s

This commit is contained in:
bytedream committed 2026-10-29 12:43:17 +01:00
1 parent c12ad5cc57
commit a6005753df
3 files changed
+20 -7

No files matched your search

+14 -2
View File
@@ -5,6 +5,17 @@ import { getJavaUuid } from '@util/minecraft.ts';
import { getSetting, SettingKey } from '@util/settings.ts';
import { sendWebhook, WebhookAction } from '@util/webhook.ts';
function getClientIp(context: { request: Request; clientAddress: string }) {
const forwardedFor = context.request.headers.get('x-forwarded-for');
if (forwardedFor) {
const ip = forwardedFor.split(',')[0].trim();
if (ip) return ip;
}
return context.clientAddress;
}
export const signup = {
signup: defineAction({
input: z.object({
@@ -20,7 +31,7 @@ export const signup = {
edition: z.enum(['java', 'bedrock']),
hash: z.string().nullish()
}),
handler: async (input) => {
handler: async (input, context) => {
// check if hash given and if so, if it's valid and nobody has already used it
if (input.hash) {
const directSignup = await db.getDirectSignupByHash({ hash: input.hash });
@@ -85,7 +96,8 @@ export const signup = {
telephone: input.phone,
username: input.username,
edition: input.edition,
uuid: uuid
uuid: uuid,
ip: getClientIp(context)
});
}
})
+1
View File
@@ -17,6 +17,7 @@ export type WebhookActionType<T extends WebhookAction> = {
username: string;
edition: 'java' | 'bedrock';
uuid: string | null;
ip: string;
};
[WebhookAction.Report]: {
reporter: string | null;