This commit is contained in:
Виталий Лавшонок
2025-10-23 18:42:47 +03:00
parent d419e06d65
commit a1576dd16f
3 changed files with 16 additions and 2 deletions

View File

@@ -3,8 +3,20 @@ import { Route, Routes } from "react-router-dom";
import Login from "../views/home/auth/Login";
import Register from "../views/home/auth/Register";
import Menu from "../views/home/menu/Menu";
import { useAppDispatch, useAppSelector } from "../redux/hooks";
import { useEffect } from "react";
import { fetchWhoAmI } from "../redux/slices/auth";
const Home = () => {
const name = useAppSelector((state) => state.auth.username);
const jwt = useAppSelector((state) => state.auth.jwt);
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(fetchWhoAmI());
}, [jwt])
return (
<div className="h-full w-full bg-liquid-background grid grid-cols-[250px,1fr] divide-x-[1px] divide-liquid-lighter">
<div className="">
@@ -15,7 +27,7 @@ const Home = () => {
<Route path="login" element={<Login />} />
<Route path="account" element={<Login />} />
<Route path="register" element={<Register />} />
<Route path="*" element={"123"} />
<Route path="*" element={name} />
</Routes>
</div>

View File

@@ -98,6 +98,7 @@ const authSlice = createSlice({
});
builder.addCase(registerUser.fulfilled, (state, action: PayloadAction<{ jwt: string; refreshToken: string }>) => {
state.status = "succeeded";
axios.defaults.headers.common['Authorization'] = `Bearer ${action.payload.jwt}`;
state.jwt = action.payload.jwt;
state.refreshToken = action.payload.refreshToken;
});
@@ -113,6 +114,7 @@ const authSlice = createSlice({
});
builder.addCase(loginUser.fulfilled, (state, action: PayloadAction<{ jwt: string; refreshToken: string }>) => {
state.status = "succeeded";
axios.defaults.headers.common['Authorization'] = `Bearer ${action.payload.jwt}`;
state.jwt = action.payload.jwt;
state.refreshToken = action.payload.refreshToken;
});

View File

@@ -24,7 +24,7 @@ const Register = () => {
useEffect(() => {
dispatch(setMenuActivePage("account"));
if (jwt) {
navigate("/home/offices");
navigate("/home");
}
}, [jwt]);