Started implementing the roles permissions
This commit is contained in:
@@ -16,6 +16,8 @@ import axios from "axios";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import {Type as UserType} from "@/interfaces/user";
|
||||
import {getGroups} from "@/utils/groups.be";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
interface BasicUser {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -28,36 +30,13 @@ interface PermissionWithBasicUsers {
|
||||
users: BasicUser[];
|
||||
}
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async (context) => {
|
||||
const {req, params} = context;
|
||||
const user = req.session.user;
|
||||
export const getServerSideProps = withIronSessionSsr(async ({req, res, params}) => {
|
||||
const user = await requestUser(req, res)
|
||||
if (!user) return redirect("/login")
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/login",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (shouldRedirectHome(user)) return redirect("/")
|
||||
|
||||
if (shouldRedirectHome(user)) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (!params?.id) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/permissions",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (!params?.id) return redirect("/permissions")
|
||||
|
||||
// Fetch data from external API
|
||||
const permission: Permission = await getPermissionDoc(params.id as string);
|
||||
@@ -100,7 +79,7 @@ export const getServerSideProps = withIronSessionSsr(async (context) => {
|
||||
id: params.id,
|
||||
users: usersData,
|
||||
},
|
||||
user: req.session.user,
|
||||
user,
|
||||
users: filteredUsers,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -8,27 +8,14 @@ import {getPermissionDocs} from "@/utils/permissions.be";
|
||||
import {User} from "@/interfaces/user";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import PermissionList from "@/components/PermissionList";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
|
||||
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("/")
|
||||
|
||||
// Fetch data from external API
|
||||
const permissions: Permission[] = await getPermissionDocs();
|
||||
@@ -51,7 +38,7 @@ export const getServerSideProps = withIronSessionSsr(async ({req}) => {
|
||||
const {users, ...rest} = p;
|
||||
return rest;
|
||||
}),
|
||||
user: req.session.user,
|
||||
user,
|
||||
},
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
Reference in New Issue
Block a user