summary refs log tree commit diff
path: root/src/api/routes/auth
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-20 03:17:44 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2022-08-20 03:17:44 +0200
commit3795c677235c74f2debf864183b71f3b76824d99 (patch)
treed0054af44901f42b4bce8611a1f027605c6dc216 /src/api/routes/auth
parentDrop ajv patch, update setup script (diff)
downloadserver-3795c677235c74f2debf864183b71f3b76824d99.tar.xz
Add fallback to bcryptjs
Diffstat (limited to 'src/api/routes/auth')
-rw-r--r--src/api/routes/auth/login.ts11
-rw-r--r--src/api/routes/auth/register.ts14
2 files changed, 19 insertions, 6 deletions
diff --git a/src/api/routes/auth/login.ts b/src/api/routes/auth/login.ts
index 9fc5924d..0fcd43de 100644
--- a/src/api/routes/auth/login.ts
+++ b/src/api/routes/auth/login.ts
@@ -1,9 +1,16 @@
 import { Request, Response, Router } from "express";
 import { route } from "@fosscord/api";
-import bcrypt from "bcrypt";
-import { Config, User, generateToken, adjustEmail, FieldErrors, LoginSchema } from "@fosscord/util";
+import { adjustEmail, Config, FieldErrors, generateToken, LoginSchema, User } from "@fosscord/util";
 import crypto from "crypto";
 
+let bcrypt: any;
+try {
+	bcrypt = require("bcrypt");
+} catch {
+	bcrypt = require("bcryptjs");
+	console.log("Warning: using bcryptjs because bcrypt is not installed! Performance will be affected.");
+}
+
 const router: Router = Router();
 export default router;
 
diff --git a/src/api/routes/auth/register.ts b/src/api/routes/auth/register.ts
index 09366a12..7d0f5f57 100644
--- a/src/api/routes/auth/register.ts
+++ b/src/api/routes/auth/register.ts
@@ -1,8 +1,14 @@
+import { getIpAdress, IPAnalysis, isProxy, route } from "@fosscord/api";
+import { adjustEmail, Config, FieldErrors, generateToken, HTTPError, Invite, RegisterSchema, User } from "@fosscord/util";
 import { Request, Response, Router } from "express";
-import { Config, generateToken, Invite, FieldErrors, User, adjustEmail, trimSpecial, RegisterSchema } from "@fosscord/util";
-import { route, getIpAdress, IPAnalysis, isProxy } from "@fosscord/api";
-import bcrypt from "bcrypt";
-import { HTTPError } from "@fosscord/util";
+
+let bcrypt: any;
+try {
+	bcrypt = require("bcrypt");
+} catch {
+	bcrypt = require("bcryptjs");
+	console.log("Warning: using bcryptjs because bcrypt is not installed! Performance will be affected.");
+}
 
 const router: Router = Router();