🐛 Fixed login page & delete forgot + register page

This commit is contained in:
2024-09-13 19:55:58 +02:00
parent 8865ba34ee
commit 6e72c029e8
9 changed files with 64 additions and 211 deletions
+48
View File
@@ -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;