Skip to content

Commit f34586c

Browse files
committed
feat: Implement user authentication and session handling
1 parent 117b6fe commit f34586c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

vite-project/src/App.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,40 @@ import RepoLayout from "@/app/repo/layout.tsx";
55
import ExploreLayout from "@/app/explore/layout.tsx";
66
import MarketLayout from "@/app/market/layout.tsx";
77
import CommunityLayout from "@/app/community/layout.tsx";
8+
import useUser from "@/state/useUser.tsx";
9+
import {useEffect} from "react";
10+
import {UserApi} from "@/api/UserApi.tsx";
11+
import {AppWrite} from "@/api/Http.tsx";
12+
import {UserModel} from "@/types.ts";
13+
import {toast} from "@pheralb/toast";
814

915
function App() {
16+
const api = new UserApi();
17+
const user = useUser();
18+
useEffect(() => {
19+
const handle = async () => {
20+
const now = await api.GetNow();
21+
const app:AppWrite<UserModel> = JSON.parse(now.data);
22+
if (app.code === 401) {
23+
if (user.dash !== undefined || user.user !== undefined) {
24+
user.logout();
25+
toast.info({
26+
text: "Login expired, please log in again",
27+
})
28+
}
29+
}
30+
};
31+
handle().then().catch()
32+
}, []);
1033
return (
1134
<Routes>
1235
<Route path={"/"} element={<RootLayout/>}>
1336
<Route path={"explore"} element={<ExploreLayout/>}/>
37+
{
38+
user.dash && (
39+
<Route path={""} element={<ExploreLayout/>}/>
40+
)
41+
}
1442
<Route path={"market"} element={<MarketLayout/>}/>
1543
<Route path={"community"} element={<CommunityLayout/>}/>
1644
<Route path={":username"} element={<LayoutUser/>}>

0 commit comments

Comments
 (0)