From fdcae013c679af08eca9b280e42724a64daf32c5 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Thu, 28 Sep 2023 19:07:25 +0330 Subject: [PATCH] added the ability to disable registration --- .env.sample | 1 + pages/api/auth/register.ts | 4 + pages/login.tsx | 20 ++-- pages/register.tsx | 221 +++++++++++++++++++------------------ types/enviornment.d.ts | 1 + 5 files changed, 132 insertions(+), 115 deletions(-) diff --git a/.env.sample b/.env.sample index a2cc611..b6eebf3 100644 --- a/.env.sample +++ b/.env.sample @@ -7,6 +7,7 @@ NEXTAUTH_URL=http://localhost:3000 PAGINATION_TAKE_COUNT= STORAGE_FOLDER= AUTOSCROLL_TIMEOUT= +NEXT_PUBLIC_DISABLE_REGISTRATION= # AWS S3 Settings SPACES_KEY= diff --git a/pages/api/auth/register.ts b/pages/api/auth/register.ts index c7e5136..7247765 100644 --- a/pages/api/auth/register.ts +++ b/pages/api/auth/register.ts @@ -20,6 +20,10 @@ export default async function Index( req: NextApiRequest, res: NextApiResponse ) { + if (process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true") { + return res.status(400).json({ response: "Registration is disabled." }); + } + const body: User = req.body; const checkHasEmptyFields = emailEnabled diff --git a/pages/login.tsx b/pages/login.tsx index 1655218..f06d3b4 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -97,15 +97,17 @@ export default function Login() { className=" w-full text-center" loading={submitLoader} /> -
-

New here?

- - Sign Up - -
+ {process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? undefined : ( +
+

New here?

+ + Sign Up + +
+ )} ); diff --git a/pages/register.tsx b/pages/register.tsx index c719cb5..75ba525 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -99,134 +99,143 @@ export default function Register() { : "Create a new account" } > -
-

- Enter your details -

-
-

- Display Name + {process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? ( +

+

+ Registration is disabled for this instance, please contact the admin + in case of any issues.

- - setForm({ ...form, name: e.target.value })} - />
- - {emailEnabled ? undefined : ( + ) : ( +
+

+ Enter your details +

- Username + Display Name

setForm({ ...form, username: e.target.value })} + onChange={(e) => setForm({ ...form, name: e.target.value })} />
- )} - {emailEnabled ? ( -
-

- Email + {emailEnabled ? undefined : ( +

+

+ Username +

+ + setForm({ ...form, username: e.target.value })} + /> +
+ )} + + {emailEnabled ? ( +
+

+ Email +

+ + setForm({ ...form, email: e.target.value })} + /> +
+ ) : undefined} + +
+

+ Password

setForm({ ...form, email: e.target.value })} + onChange={(e) => setForm({ ...form, password: e.target.value })} />
- ) : undefined} -
-

- Password -

- - setForm({ ...form, password: e.target.value })} - /> -
- -
-

- Confirm Password -

- - - setForm({ ...form, passwordConfirmation: e.target.value }) - } - /> -
- - {process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE ? ( -
-

- By signing up, you agree to our{" "} - - Terms of Service - {" "} - and{" "} - - Privacy Policy - - . -

-

- Need help?{" "} - - Get in touch - - . +

+

+ Confirm Password

+ + + setForm({ ...form, passwordConfirmation: e.target.value }) + } + />
- ) : undefined} - -
-

- Already have an account? -

- - Login - + {process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE ? ( +
+

+ By signing up, you agree to our{" "} + + Terms of Service + {" "} + and{" "} + + Privacy Policy + + . +

+

+ Need help?{" "} + + Get in touch + + . +

+
+ ) : undefined} + + +
+

+ Already have an account? +

+ + Login + +
-
+ )} ); } diff --git a/types/enviornment.d.ts b/types/enviornment.d.ts index 946b2a8..8e4c9db 100644 --- a/types/enviornment.d.ts +++ b/types/enviornment.d.ts @@ -4,6 +4,7 @@ declare global { NEXTAUTH_SECRET: string; DATABASE_URL: string; NEXTAUTH_URL: string; + NEXT_PUBLIC_DISABLE_REGISTRATION?: string; PAGINATION_TAKE_COUNT?: string; STORAGE_FOLDER?: string; AUTOSCROLL_TIMEOUT?: string;