diff --git a/index.html b/index.html
index a094d6a..8810eea 100644
--- a/index.html
+++ b/index.html
@@ -2,9 +2,9 @@
-
+
- Vite + React + TS
+ Livro Livre Admin
diff --git a/public/logo.png b/public/logo.png
new file mode 100644
index 0000000..90ec9ab
Binary files /dev/null and b/public/logo.png differ
diff --git a/public/vite.svg b/public/vite.svg
deleted file mode 100644
index e7b8dfb..0000000
--- a/public/vite.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/src/App.tsx b/src/App.tsx
index 7a741b8..985ad8a 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -16,6 +16,7 @@ function App() {
} />
+ } />
} />
} />
} />
diff --git a/src/PrivateRoute.tsx b/src/PrivateRoute.tsx
index caf38f0..190837a 100644
--- a/src/PrivateRoute.tsx
+++ b/src/PrivateRoute.tsx
@@ -4,12 +4,12 @@ import { useEffect } from "react";
const PrivateRoute = ({ children }: { children: any }) => {
const navigate = useNavigate();
- const { token } = useAuth();
+ const { isAuthenticated } = useAuth();
useEffect(() => {
- if (token) return;
+ if (isAuthenticated) return;
navigate('/login');
- })
+ }, [isAuthenticated])
return children;
}
diff --git a/src/hooks/useApi/index.tsx b/src/hooks/useApi/index.tsx
index 2da0a66..eae67ea 100644
--- a/src/hooks/useApi/index.tsx
+++ b/src/hooks/useApi/index.tsx
@@ -45,7 +45,7 @@ const useApi = () => {
getUsers: (data: {
perPage: number;
page: number
- }): Promise<{ data: {
+ }, token: string | null): Promise<{ data: {
items: User[],
total: number,
} }> => {
@@ -55,6 +55,9 @@ const useApi = () => {
params: {
perPage: data.perPage,
page: data.page,
+ },
+ headers: {
+ Authorization: `Bearer ${token}`,
}
})
.then((res) => resolve(res))
diff --git a/src/pages/SignIn/SignInForm/index.tsx b/src/pages/SignIn/SignInForm/index.tsx
index a5e1571..ee96c4a 100644
--- a/src/pages/SignIn/SignInForm/index.tsx
+++ b/src/pages/SignIn/SignInForm/index.tsx
@@ -22,7 +22,7 @@ function SignInForm() {
formState: { errors, isValid },
} = useForm();
- const { signIn, token } = useAuth();
+ const { signIn, isAuthenticated } = useAuth();
const onSubmit = handleSubmit(async (data: FormValues) => {
setLoading(true);
@@ -34,9 +34,9 @@ function SignInForm() {
})
useEffect(() => {
- if (!token) return;
+ if (!isAuthenticated) return;
navigate('/inicio');
- }, [token])
+ }, [isAuthenticated])
return (