summary refs log tree commit diff
path: root/src/api
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2026-06-11 00:04:10 +0200
committerRory& <root@rory.gay>2026-06-11 00:04:10 +0200
commit02d93d2a920d3998a9a35aef1746abb15039f7bc (patch)
tree6b6b59defcf278d34025179d0bc163697f069e5c /src/api
parentClean up tests a little (diff)
downloadserver-ts-02d93d2a920d3998a9a35aef1746abb15039f7bc.tar.xz
Trace registration
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/auth/register.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts

index 79929f5e..1427b3c6 100644 --- a/src/api/routes/auth/register.ts +++ b/src/api/routes/auth/register.ts
@@ -17,7 +17,7 @@ */ import { route, verifyCaptcha } from "@spacebar/api"; -import { Config, FieldErrors, Invite, User, ValidRegistrationToken, generateToken, IpDataClient, AbuseIpDbClient, TimeSpan } from "@spacebar/util"; +import { Config, FieldErrors, Invite, User, ValidRegistrationToken, generateToken, IpDataClient, AbuseIpDbClient, TimeSpan, Stopwatch } from "@spacebar/util"; import bcrypt from "bcrypt"; import { Request, Response, Router } from "express"; import { HTTPError } from "lambert-server"; @@ -45,6 +45,13 @@ router.post( }, }), async (req: Request, res: Response) => { + const totalSw = Stopwatch.startNew(); + const incSw = Stopwatch.startNew(); + const logTrace = (...data: unknown[]) => { + if (process.env.LOG_VERBOSE_TRACES !== "true") return; + console.log("[Register]", ...data, `[${totalSw.elapsed().toString()} (+${incSw.getElapsedAndReset().totalMilliseconds}ms)]`); + }; + const body = req.body as RegisterSchema; const { register, security, limits } = Config.get(); const ip = req.ip!; @@ -133,6 +140,8 @@ router.post( } } + logTrace("Basic checks"); + //region IP checks const cacheBlockedIp = (ip: string, reason: string) => { recentlyBlockedIps[ip] = { @@ -206,6 +215,7 @@ router.post( } } //endregion + logTrace("IP checks"); // TODO: gift_code_sku_id? // TODO: check password strength @@ -242,6 +252,8 @@ router.post( }); } + logTrace("Email checks"); + if (register.dateOfBirth.required && !body.date_of_birth) { throw FieldErrors({ date_of_birth: { @@ -302,6 +314,7 @@ router.post( }, }); } + logTrace("Password checks"); if (!regTokenUsed && !body.invite && (register.requireInvite || (register.guestsRequireInvite && !register.email))) { // require invite to register -> e.g. for organizations to send invites to their employees @@ -330,6 +343,7 @@ router.post( }, }); } + logTrace("Absolute register rate checks"); const { maxUsername } = Config.get().limits.user; if (body.username.length > maxUsername) { @@ -342,13 +356,16 @@ router.post( } const user = await User.register({ ...body, req }); + logTrace("Register user"); if (body.invite) { // await to fail if the invite doesn't exist (necessary for requireInvite to work properly) (username only signups are possible) await Invite.joinGuild(user.id, body.invite); + logTrace("Accept invite"); } - return res.json({ token: await generateToken(user.id) }); + res.json({ token: await generateToken(user.id) }); + logTrace("Generate token"); }, );