Skip to content

Commit 01df3f6

Browse files
committed
add deviceid to Login title
1 parent 21329b3 commit 01df3f6

2 files changed

Lines changed: 59 additions & 23 deletions

File tree

frontend/dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Nurse Raw Dashboard</title>
8-
<script type="module" crossorigin src="/assets/index-Dr-BW-Dm.js"></script>
8+
<script type="module" crossorigin src="/assets/index-fsqbhejo.js"></script>
99
<link rel="stylesheet" crossorigin href="/assets/index-uwqVlDTL.css">
1010
</head>
1111
<body class="bg-gray-50 text-gray-900">

frontend/src/pages/Home.tsx

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import { useEffect, useState } from "react";
2-
import { Link, useLocation } from "react-router-dom";
2+
import { Link } from "react-router-dom";
33

44
export default function Home() {
55
const [darkMode, setDarkMode] = useState(() => {
66
const stored = localStorage.getItem("darkMode");
77
return stored ? JSON.parse(stored) : false;
88
});
99

10-
const location = useLocation();
10+
const [user, setUser] = useState<{ username: string } | null>(null);
1111

12+
// Проверка токена
1213
useEffect(() => {
13-
if (darkMode) {
14-
document.documentElement.classList.add("dark");
15-
} else {
16-
document.documentElement.classList.remove("dark");
17-
}
14+
const token = localStorage.getItem("token");
15+
if (!token) return;
16+
17+
fetch("/api/auth/me", {
18+
headers: { Authorization: `Bearer ${token}` },
19+
})
20+
.then(async (res) => {
21+
if (res.ok) {
22+
const data = await res.json();
23+
setUser(data);
24+
} else {
25+
setUser(null);
26+
}
27+
})
28+
.catch(() => setUser(null));
29+
}, []);
30+
31+
// Dark mode toggle
32+
useEffect(() => {
33+
if (darkMode) document.documentElement.classList.add("dark");
34+
else document.documentElement.classList.remove("dark");
1835
localStorage.setItem("darkMode", JSON.stringify(darkMode));
1936
}, [darkMode]);
2037

@@ -73,21 +90,40 @@ export default function Home() {
7390
)}
7491
</button>
7592

76-
<Link to="/login" className="login-button">
77-
<svg
78-
viewBox="0 0 24 24"
79-
xmlns="http://www.w3.org/2000/svg"
80-
className="button-icon"
81-
>
82-
<path
83-
fill="currentColor"
84-
fillRule="evenodd"
85-
d="M7.5 6.75a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM3.751 20.25a8.25 8.25 0 0116.498 0 .75.75 0 01-.75.75h-15a.75.75 0 01-.75-.75z"
86-
clipRule="evenodd"
87-
/>
88-
</svg>
89-
<span>Login</span>
90-
</Link>
93+
{/* Авторизация */}
94+
{user ? (
95+
<Link to="/dashboard" className="login-button">
96+
<svg
97+
viewBox="0 0 24 24"
98+
xmlns="http://www.w3.org/2000/svg"
99+
className="button-icon"
100+
>
101+
<path
102+
fill="currentColor"
103+
fillRule="evenodd"
104+
d="M7.5 6.75a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM3.751 20.25a8.25 8.25 0 0116.498 0 .75.75 0 01-.75.75h-15a.75.75 0 01-.75-.75z"
105+
clipRule="evenodd"
106+
/>
107+
</svg>
108+
<span>{user.username}</span>
109+
</Link>
110+
) : (
111+
<Link to="/login" className="login-button">
112+
<svg
113+
viewBox="0 0 24 24"
114+
xmlns="http://www.w3.org/2000/svg"
115+
className="button-icon"
116+
>
117+
<path
118+
fill="currentColor"
119+
fillRule="evenodd"
120+
d="M7.5 6.75a4.5 4.5 0 119 0 4.5 4.5 0 01-9 0zM3.751 20.25a8.25 8.25 0 0116.498 0 .75.75 0 01-.75.75h-15a.75.75 0 01-.75-.75z"
121+
clipRule="evenodd"
122+
/>
123+
</svg>
124+
<span>Login</span>
125+
</Link>
126+
)}
91127
</div>
92128
</div>
93129
</nav>

0 commit comments

Comments
 (0)