Skip to content

Commit 3495b1a

Browse files
committed
Auth and instances implementation
Implements authentication functionality and creates instances service - Modifies package-lock.json, package.json, footer.tsx, header.tsx - Adds protected-route.tsx, public-route.tsx to src/components/providers - Modifies Dashboard/index.tsx, Login/index.tsx, routes/index.tsx - Adds auth.service.ts, instances.service.ts to src/services - Adds instance.ts to src/utils This commit enhances the application's authentication process and introduces instances management, improving user experience and enabling further features.
1 parent 6a5c712 commit 3495b1a

File tree

12 files changed

+407
-285
lines changed

12 files changed

+407
-285
lines changed

package-lock.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@radix-ui/react-switch": "^1.1.0",
2424
"@radix-ui/react-tabs": "^1.1.0",
2525
"@radix-ui/react-toast": "^1.2.1",
26+
"axios": "^1.7.2",
2627
"class-variance-authority": "^0.7.0",
2728
"clsx": "^2.1.1",
2829
"cmdk": "^1.0.0",

src/components/footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function Footer() {
55
<footer className="footer">
66
<div className="footer-info">
77
Client Name: <strong>Evolution Manager</strong> Version:{" "}
8-
<strong>1.0.0</strong>
8+
<strong>{localStorage.getItem("version")}</strong>
99
</div>
1010
<div className="footer-buttons">
1111
<Button variant="link">

src/components/header.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { logout } from "@/services/auth.service";
12
import { DoorOpen } from "lucide-react";
23
import { useNavigate } from "react-router-dom";
34

@@ -9,6 +10,7 @@ function Header({ perfil }: HeaderProps) {
910
const navigate = useNavigate();
1011

1112
const handleClose = () => {
13+
logout();
1214
navigate("/login");
1315
};
1416
return (
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { Navigate } from "react-router-dom";
3+
4+
type ProtectedRouteProps = {
5+
children: React.ReactNode;
6+
};
7+
8+
const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
9+
const apiUrl = localStorage.getItem("apiUrl");
10+
const token = localStorage.getItem("token");
11+
const version = localStorage.getItem("version");
12+
13+
if (!apiUrl || !token || !version) {
14+
return <Navigate to="/login" />;
15+
}
16+
17+
return children;
18+
};
19+
20+
export default ProtectedRoute;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import { Navigate } from "react-router-dom";
3+
4+
type PublicRouteProps = {
5+
children: React.ReactNode;
6+
};
7+
8+
const PublicRoute = ({ children }: PublicRouteProps) => {
9+
const apiUrl = localStorage.getItem("apiUrl");
10+
const token = localStorage.getItem("token");
11+
const version = localStorage.getItem("version");
12+
13+
if (apiUrl && token && version) {
14+
return <Navigate to="/" />;
15+
}
16+
17+
return children;
18+
};
19+
20+
export default PublicRoute;

0 commit comments

Comments
 (0)