⚡ Upgrade design & moved backend here & login and settings work with api
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
//! Imports
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// -------------------------------------------------- React & Next -----------------------------------------------------
|
||||
import { useEffect, useState } from 'react';
|
||||
import { redirect, usePathname } from 'next/navigation';
|
||||
import Navbar from '@/components/Navbar/Navbar';
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
const Provider = ({ children }) => {
|
||||
const pathname = usePathname();
|
||||
const [isSuccess, setIsSuccess] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (pathname.startsWith('/auth')) {
|
||||
setIsSuccess(true);
|
||||
return;
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (!token) {
|
||||
redirect('/auth/login');
|
||||
}
|
||||
|
||||
setIsSuccess(true);
|
||||
}, [pathname]);
|
||||
|
||||
if (!isSuccess) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathname.startsWith('/auth')) {
|
||||
return children;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
<Navbar />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Provider;
|
||||
Reference in New Issue
Block a user