Made sure the user can’t navigate to another page when they shouldn’t via the URL

This commit is contained in:
Tiago Ribeiro
2023-10-12 10:00:44 +01:00
parent 1d27da71ec
commit 4c95d85cf9
9 changed files with 74 additions and 292 deletions

View File

@@ -21,6 +21,7 @@ import Select from "react-select";
import useGroups from "@/hooks/useGroups";
import DatePicker from "react-datepicker";
import moment from "moment";
import {shouldRedirectHome} from "@/utils/navigation.disabled";
ChartJS.register(LinearScale, CategoryScale, PointElement, LineElement, LineController, Legend, Tooltip);
@@ -40,6 +41,17 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
};
}
if (shouldRedirectHome(user)) {
res.setHeader("location", "/");
res.statusCode = 302;
res.end();
return {
props: {
user: null,
},
};
}
return {
props: {user: req.session.user},
};