refactor: handle authentication state in middleware
This commit is contained in:
@@ -1,24 +1,12 @@
|
||||
import { useRouter } from "next/router";
|
||||
import SignUpForm from "../../components/auth/SignUpForm";
|
||||
import Meta from "../../components/Meta";
|
||||
import useConfig from "../../hooks/config.hook";
|
||||
import useUser from "../../hooks/user.hook";
|
||||
|
||||
const SignUp = () => {
|
||||
const config = useConfig();
|
||||
const { user } = useUser();
|
||||
const router = useRouter();
|
||||
if (user) {
|
||||
router.replace("/");
|
||||
} else if (!config.get("ALLOW_REGISTRATION")) {
|
||||
router.replace("/auth/signIn");
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
<Meta title="Sign Up" />
|
||||
<SignUpForm />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Meta title="Sign Up" />
|
||||
<SignUpForm />
|
||||
</>
|
||||
);
|
||||
};
|
||||
export default SignUp;
|
||||
|
||||
Reference in New Issue
Block a user