feat(platform): add Discord onboarding and Velocity gate
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { getClientIp } from "@minecraft-account-manager/network";
|
||||
import { ipObservations, recordEvent } from "@minecraft-account-manager/database";
|
||||
import { headers } from "next/headers";
|
||||
import { db } from "@/lib/database";
|
||||
|
||||
const UI_ACCESSED = "games.minecraft.account-manager.ui.accessed";
|
||||
|
||||
export async function recordUserEvent(
|
||||
user: { id: string },
|
||||
type: string,
|
||||
data: Record<string, unknown>,
|
||||
) {
|
||||
const requestHeaders = await headers();
|
||||
const ipAddress = getClientIp(requestHeaders, process.env.TRUST_PROXY === "true");
|
||||
return recordEvent(db, {
|
||||
type,
|
||||
source: "/web",
|
||||
subject: `user/${user.id}`,
|
||||
actorUserId: user.id,
|
||||
ipAddress: ipAddress ?? undefined,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordAuthenticatedUiAccess(
|
||||
user: { id: string },
|
||||
path: string,
|
||||
) {
|
||||
const requestHeaders = await headers();
|
||||
const ipAddress = getClientIp(requestHeaders, process.env.TRUST_PROXY === "true");
|
||||
|
||||
await Promise.all([
|
||||
recordEvent(db, {
|
||||
type: UI_ACCESSED,
|
||||
source: "/web",
|
||||
subject: `user/${user.id}`,
|
||||
actorUserId: user.id,
|
||||
ipAddress: ipAddress ?? undefined,
|
||||
data: { path },
|
||||
}),
|
||||
ipAddress
|
||||
? db.insert(ipObservations).values({
|
||||
userId: user.id,
|
||||
source: "web",
|
||||
ipAddress,
|
||||
classification: "unknown",
|
||||
})
|
||||
: Promise.resolve(),
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user