update: route
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
import React from 'react';
|
||||
import { Navigate, Outlet } from 'react-router-dom';
|
||||
import MainLayout from './layout/MainLayout';
|
||||
|
||||
import { getSessionData } from './components/Global/Formatter';
|
||||
import { NotifAlert } from './components/Global/ToastNotif';
|
||||
|
||||
export const ProtectedRoute = () => {
|
||||
const session = getSessionData();
|
||||
// console.log(session);
|
||||
// cek token di localStorage
|
||||
const token = localStorage.getItem('token');
|
||||
const isAuthenticated = !!token;
|
||||
|
||||
const isAuthenticated = session?.auth ?? false;
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/signin" replace />;
|
||||
}
|
||||
return (
|
||||
<MainLayout>
|
||||
<Outlet />
|
||||
</MainLayout>
|
||||
);
|
||||
if (!isAuthenticated) {
|
||||
NotifAlert({
|
||||
icon: 'warning',
|
||||
title: 'Session Habis',
|
||||
message: 'Silahkan login terlebih dahulu',
|
||||
});
|
||||
return <Navigate to="/signin" replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
<MainLayout>
|
||||
<Outlet />
|
||||
</MainLayout>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user