|
@@ -1,54 +1,26 @@
|
|
|
import { Navigate, useLocation } from 'react-router-dom';
|
|
import { Navigate, useLocation } from 'react-router-dom';
|
|
|
import { useSelector } from 'react-redux';
|
|
import { useSelector } from 'react-redux';
|
|
|
-import jwt_decode from "jwt-decode";
|
|
|
|
|
|
|
|
|
|
-const Recluter = {
|
|
|
|
|
- authorities: "Reclutador",
|
|
|
|
|
- app_name: 'Dashboard',
|
|
|
|
|
- type: 1
|
|
|
|
|
-}
|
|
|
|
|
|
|
+export function RequireUserToken({ children }) {
|
|
|
|
|
+
|
|
|
|
|
+ let token = useSelector((state) => state.token.candi)
|
|
|
|
|
+ let location = useLocation();
|
|
|
|
|
|
|
|
-const User = {
|
|
|
|
|
- authorities: "User",
|
|
|
|
|
- app_name: 'User',
|
|
|
|
|
- type: 2
|
|
|
|
|
|
|
+ if (!token) {
|
|
|
|
|
+ return <Navigate to="/logincd" state={{ from: location }} replace />;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return children;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
export function RequireToken({ children }) {
|
|
export function RequireToken({ children }) {
|
|
|
|
|
|
|
|
let token = useSelector((state) => state.token.token)
|
|
let token = useSelector((state) => state.token.token)
|
|
|
let location = useLocation();
|
|
let location = useLocation();
|
|
|
- let app_name = children?.type?.name
|
|
|
|
|
|
|
|
|
|
if (!token) {
|
|
if (!token) {
|
|
|
- if (app_name === Recluter.app_name) {
|
|
|
|
|
- return <Navigate to="/login" state={{ from: location }} replace />;
|
|
|
|
|
- } else {
|
|
|
|
|
- return <Navigate to="/logincd" state={{ from: location }} replace />;
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
-
|
|
|
|
|
- let body_token = jwt_decode(token);
|
|
|
|
|
- let token_access = body_token?.authorities;
|
|
|
|
|
-
|
|
|
|
|
- if (app_name === User.app_name) {
|
|
|
|
|
- let valid_user = token_access.includes(User.authorities);
|
|
|
|
|
- if (!valid_user) {
|
|
|
|
|
- return <Navigate to="/logincd" state={{ from: location }} replace />;
|
|
|
|
|
- } else {
|
|
|
|
|
- return children;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (app_name === Recluter.app_name) {
|
|
|
|
|
- let valid_user = token_access.includes(Recluter.authorities);
|
|
|
|
|
- if (!valid_user) {
|
|
|
|
|
- return <Navigate to="/logincd" state={{ from: location }} replace />;
|
|
|
|
|
- } else {
|
|
|
|
|
- return children;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ return <Navigate to="/login" state={{ from: location }} replace />;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return children;
|
|
return children;
|