Refactor HomePage to use custom Button component; enhance login service to fetch user with full relations for improved data handling.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import Button from "../components/ui/Button";
|
||||||
import { useMe, useLogout } from "../hooks/useAuth";
|
import { useMe, useLogout } from "../hooks/useAuth";
|
||||||
import { useNavigate } from "react-router";
|
import { useNavigate } from "react-router";
|
||||||
|
|
||||||
@@ -70,13 +71,13 @@ function HomePage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
<Button
|
||||||
onClick={handleLogout}
|
onClick={handleLogout}
|
||||||
disabled={logoutMutation.isPending}
|
disabled={logoutMutation.isPending}
|
||||||
className="px-4 py-2 text-white bg-red-600 rounded-md hover:bg-red-700 disabled:opacity-50"
|
className="px-4 py-2 text-white bg-red-600 rounded-md hover:bg-red-700 disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{logoutMutation.isPending ? "Выход..." : "Выйти"}
|
{logoutMutation.isPending ? "Выход..." : "Выйти"}
|
||||||
</button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,12 +37,17 @@ export const loginService = {
|
|||||||
metadata
|
metadata
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Получить пользователя с полными данными (филиал и компания)
|
||||||
|
const userWithRelations = await userService.findByIdWithRelations(user.id);
|
||||||
|
|
||||||
// Вычислить дату истечения токена
|
// Вычислить дату истечения токена
|
||||||
const expiresAt = new Date();
|
const expiresAt = new Date();
|
||||||
expiresAt.setDate(expiresAt.getDate() + 7);
|
expiresAt.setDate(expiresAt.getDate() + 7);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
user: userService.sanitize(user),
|
user: userWithRelations
|
||||||
|
? userService.sanitizeWithRelations(userWithRelations)
|
||||||
|
: userService.sanitize(user),
|
||||||
session: {
|
session: {
|
||||||
id: sessionId,
|
id: sessionId,
|
||||||
token: accessToken,
|
token: accessToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user