Updated the register to only allow to create users if they have a code available
This commit is contained in:
@@ -11,12 +11,23 @@ import axios from "axios";
|
||||
import {Divider} from "primereact/divider";
|
||||
import {useRouter} from "next/router";
|
||||
import clsx from "clsx";
|
||||
import {NextPageContext} from "next";
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
|
||||
export default function Register() {
|
||||
export const getServerSideProps = (context: any) => {
|
||||
const {code} = context.query;
|
||||
|
||||
return {
|
||||
props: {code},
|
||||
};
|
||||
};
|
||||
|
||||
export default function Register({code: queryCode}: {code: string}) {
|
||||
const [name, setName] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [code, setCode] = useState(queryCode || "");
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
@@ -40,6 +51,7 @@ export default function Register() {
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
code,
|
||||
profilePicture: "/defaultAvatar.png",
|
||||
})
|
||||
.then((response) => {
|
||||
@@ -52,6 +64,12 @@ export default function Register() {
|
||||
toast.error("There is already a user with that e-mail!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (error.response.status === 400) {
|
||||
toast.error("The provided code is invalid!");
|
||||
return;
|
||||
}
|
||||
|
||||
toast.error("There was something wrong, please try again!");
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
@@ -95,10 +113,11 @@ export default function Register() {
|
||||
defaultValue={confirmPassword}
|
||||
required
|
||||
/>
|
||||
<Input type="text" name="code" onChange={(e) => setCode(e)} placeholder="Enter your registration code" defaultValue={code} required />
|
||||
<Button
|
||||
className="lg:mt-8 w-full"
|
||||
color="purple"
|
||||
disabled={isLoading || !email || !name || !password || !confirmPassword || password !== confirmPassword}>
|
||||
disabled={isLoading || !email || !name || !password || !confirmPassword || password !== confirmPassword || !code}>
|
||||
Create account
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user