Started implementing the roles permissions
This commit is contained in:
@@ -17,29 +17,16 @@ import CardList from "@/components/High/CardList";
|
||||
import {getEntitiesWithRoles} from "@/utils/entities.be";
|
||||
import {EntityWithRoles} from "@/interfaces/entity";
|
||||
import Separator from "@/components/Low/Separator";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
|
||||
type EntitiesWithCount = {entity: EntityWithRoles; users: User[]; count: number};
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req}) => {
|
||||
const user = req.session.user;
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
const user = await requestUser(req, res)
|
||||
if (!user) return redirect("/login")
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/login",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (shouldRedirectHome(user)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (shouldRedirectHome(user)) return redirect("/")
|
||||
|
||||
const entities = await getEntitiesWithRoles(
|
||||
checkAccess(user, getTypesOfUser(["admin", "developer"])) ? user.entities.map((x) => x.id) : undefined,
|
||||
@@ -99,18 +86,21 @@ export default function Home({user, entities}: Props) {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<ToastContainer />
|
||||
{user && (
|
||||
<Layout user={user} className="!gap-4">
|
||||
<section className="flex flex-col gap-4 w-full h-full">
|
||||
<div className="flex flex-col gap-4">
|
||||
<h2 className="font-bold text-2xl">Entities</h2>
|
||||
<Separator />
|
||||
</div>
|
||||
<Layout user={user} className="!gap-4">
|
||||
<section className="flex flex-col gap-4 w-full h-full">
|
||||
<div className="flex flex-col gap-4">
|
||||
<h2 className="font-bold text-2xl">Entities</h2>
|
||||
<Separator />
|
||||
</div>
|
||||
|
||||
<CardList<EntitiesWithCount> list={entities} searchFields={SEARCH_FIELDS} renderCard={renderCard} firstCard={firstCard} />
|
||||
</section>
|
||||
</Layout>
|
||||
)}
|
||||
<CardList<EntitiesWithCount>
|
||||
list={entities}
|
||||
searchFields={SEARCH_FIELDS}
|
||||
renderCard={renderCard}
|
||||
firstCard={["admin", "developer"].includes(user.type) ? firstCard : undefined}
|
||||
/>
|
||||
</section>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user