summary refs log tree commit diff
path: root/api/src/routes/auth
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 14:31:23 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-10-09 14:31:23 +0200
commit7aeeb6833d72ce63d699d693a8d18b9a85d0c69f (patch)
tree562cdfd1255bf538093581a9357076232880cfce /api/src/routes/auth
parent:bug: fix array key in config (diff)
parentMerge pull request #429 from fosscord/dev (diff)
downloadserver-ts-7aeeb6833d72ce63d699d693a8d18b9a85d0c69f.tar.xz
Merge branch 'master' of http://github.com/fosscord/fosscord-server
Diffstat (limited to 'api/src/routes/auth')
-rw-r--r--api/src/routes/auth/register.ts15
1 files changed, 9 insertions, 6 deletions
diff --git a/api/src/routes/auth/register.ts b/api/src/routes/auth/register.ts

index 9f3b46f1..cd1bcb72 100644 --- a/api/src/routes/auth/register.ts +++ b/api/src/routes/auth/register.ts
@@ -98,7 +98,6 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re } } - console.log("register", body.email, body.username, ip); // TODO: gift_code_sku_id? // TODO: check password strength @@ -154,18 +153,22 @@ router.post("/", route({ body: "RegisterSchema" }), async (req: Request, res: Re }); } + if (!body.invite && (register.requireInvite || (register.guestsRequireInvite && !register.email))) { + // require invite to register -> e.g. for organizations to send invites to their employees + throw FieldErrors({ + email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") } + }); + } + const user = await User.register({ ...body, req }); 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); - } else if (register.requireInvite) { - // require invite to register -> e.g. for organizations to send invites to their employees - throw FieldErrors({ - email: { code: "INVITE_ONLY", message: req.t("auth:register.INVITE_ONLY") } - }); } + console.log("register", body.email, body.username, ip); + return res.json({ token: await generateToken(user.id) }); });