Updated redirect implementation

This commit is contained in:
Joao Ramos
2024-03-11 17:00:38 +00:00
parent 330c177ff9
commit 37c3c6f7f4
14 changed files with 111 additions and 150 deletions

View File

@@ -35,6 +35,7 @@ import Select from "react-select";
import {USER_TYPE_LABELS} from "@/resources/user";
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
debugger;
const user = req.session.user;
const envVariables: {[key: string]: string} = {};
@@ -45,14 +46,11 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
});
if (!user || !user.isVerified) {
res.setHeader("location", "/login");
res.statusCode = 302;
res.end();
return {
props: {
user: null,
envVariables,
},
redirect: {
destination: "/login",
permanent: false,
}
};
}
@@ -61,7 +59,13 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
};
}, sessionOptions);
export default function Home({envVariables}: {envVariables: {[key: string]: string}}) {
interface Props {
user: any;
envVariables: {[key: string]: string};
}
export default function Home(props: Props) {
const { envVariables} = props;
debugger;
const [showDiagnostics, setShowDiagnostics] = useState(false);
const [showDemographicInput, setShowDemographicInput] = useState(false);
const [selectedScreen, setSelectedScreen] = useState<Type>("admin");