Add disable registration option
This commit is contained in:
@@ -27,13 +27,13 @@ function App(props: AppProps & { colorScheme: ColorScheme }) {
|
||||
);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isSignedIn, setIsSignedIn] = useState(false);
|
||||
|
||||
let environmentVariables: any = {};
|
||||
const [environmentVariables, setEnvironmentVariables] = useState<any>({});
|
||||
|
||||
const getInitalData = async () => {
|
||||
setIsLoading(true);
|
||||
environmentVariables = await configUtil.getGonfig();
|
||||
const environmentVariables = await configUtil.getGonfig();
|
||||
aw.setEndpoint(environmentVariables.APPWRITE_HOST);
|
||||
setEnvironmentVariables(environmentVariables);
|
||||
setIsSignedIn(await authUtil.isSignedIn());
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
@@ -2,9 +2,15 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
let publicEnvironmentVariables: any = {};
|
||||
Object.entries(process.env).forEach(([key, value]) => {
|
||||
if (key.startsWith("PUBLIC")) {
|
||||
Object.entries(process.env).forEach(([key, value]: any) => {
|
||||
value as string | number | boolean;
|
||||
if (key.startsWith("PUBLIC") && value) {
|
||||
key = key.replace("PUBLIC_", "");
|
||||
if (value == "false" || value == "true") {
|
||||
value = JSON.parse(value);
|
||||
} else if (!isNaN(Number(value))) {
|
||||
value = parseInt(value as string);
|
||||
}
|
||||
publicEnvironmentVariables[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,12 +3,16 @@ import React, { useContext } from "react";
|
||||
import AuthForm from "../../components/auth/AuthForm";
|
||||
import Meta from "../../components/Meta";
|
||||
import { IsSignedInContext } from "../../utils/auth.util";
|
||||
import { useConfig } from "../../utils/config.util";
|
||||
|
||||
const SignUp = () => {
|
||||
const isSignedIn = useContext(IsSignedInContext);
|
||||
const config = useConfig();
|
||||
const router = useRouter();
|
||||
if (isSignedIn) {
|
||||
router.replace("/");
|
||||
} else if (config.DISABLE_REGISTRATION) {
|
||||
router.replace("/auth/signIn");
|
||||
} else {
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -76,7 +76,6 @@ const Upload = () => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (!isSignedIn) {
|
||||
router.replace("/");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user