summary refs log tree commit diff
path: root/src/routes/auth
diff options
context:
space:
mode:
authorDiego Magdaleno <diegomagdaleno@protonmail.com>2021-05-19 20:39:31 -0500
committerDiego Magdaleno <diegomagdaleno@protonmail.com>2021-05-19 20:39:31 -0500
commite3f6a29df79865ae9a0d842ba5d59a2851894081 (patch)
tree079b93be825cae82a66912c61d38a5fbb28f87be /src/routes/auth
parentConfig: Start working on the config refactor (diff)
downloadserver-e3f6a29df79865ae9a0d842ba5d59a2851894081.tar.xz
Config: First rewrite of config and working implementation of getting values
Diffstat (limited to 'src/routes/auth')
-rw-r--r--src/routes/auth/login.ts9
-rw-r--r--src/routes/auth/register.ts9
2 files changed, 11 insertions, 7 deletions
diff --git a/src/routes/auth/login.ts b/src/routes/auth/login.ts

index a0fc1190..218a56ae 100644 --- a/src/routes/auth/login.ts +++ b/src/routes/auth/login.ts
@@ -3,7 +3,7 @@ import { check, FieldErrors, Length } from "../../util/instanceOf"; import bcrypt from "bcrypt"; import jwt from "jsonwebtoken"; import { UserModel } from "@fosscord/server-util"; -import Config from "../../util/Config"; +import * as Config from "../../util/Config"; import { adjustEmail } from "./register"; const router: Router = Router(); @@ -25,7 +25,9 @@ router.post( const query: any[] = [{ phone: login }]; if (email) query.push({ email }); - const config = Config.get(); + // TODO: Rewrite this to have the proper config syntax on the new method + + const config = Config.apiConfig.store as unknown as Config.DefaultOptions; if (config.login.requireCaptcha && config.security.captcha.enabled) { if (!captcha_key) { @@ -67,9 +69,10 @@ export async function generateToken(id: string) { const algorithm = "HS256"; return new Promise((res, rej) => { + const securityPropertiesSecret = Config.apiConfig.get('security.jwtSecret') as Config.DefaultOptions; jwt.sign( { id: id, iat }, - Config.get().security.jwtSecret, + securityPropertiesSecret.security.jwtSecret, { algorithm, }, diff --git a/src/routes/auth/register.ts b/src/routes/auth/register.ts
index 265516d7..6389fb22 100644 --- a/src/routes/auth/register.ts +++ b/src/routes/auth/register.ts
@@ -1,5 +1,5 @@ import { Request, Response, Router } from "express"; -import Config from "../../util/Config"; +import * as Config from "../../util/Config"; import { trimSpecial, User, Snowflake, UserModel } from "@fosscord/server-util"; import bcrypt from "bcrypt"; import { check, Email, EMAIL_REGEX, FieldErrors, Length } from "../../util/instanceOf"; @@ -52,7 +52,8 @@ router.post( let discriminator = ""; // get register Config - const { register, security } = Config.get(); + const securityProperties = Config.apiConfig.store as unknown as Config.DefaultOptions; + const { register, security } = securityProperties; // check if registration is allowed if (!register.allowNewRegistration) { @@ -90,13 +91,13 @@ router.post( }, }); } - } else if (register.email.required) { + } else if (register.email.necessary) { throw FieldErrors({ email: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }, }); } - if (register.dateOfBirth.required && !date_of_birth) { + if (register.dateOfBirth.necessary && !date_of_birth) { throw FieldErrors({ date_of_birth: { code: "BASE_TYPE_REQUIRED", message: req.t("common:field.BASE_TYPE_REQUIRED") }, });