add: added an auth middleware to simplify code

This commit is contained in:
Lukian 2025-04-03 12:30:17 +02:00
parent c34df6609c
commit e0efe57f5c
9 changed files with 104 additions and 70 deletions

View file

@ -19,25 +19,48 @@ export default function Home() {
setUser(res.data)
})
.catch((err) => {
console.error(err)
console.error(err.response)
})
}
}
axios
.get("/api/channels").then((res) => {
.get("/api/channels")
.then((res) => {
setChannels(res.data)
})
.catch((err) => {
console.error(err)
console.error(err.response)
})
axios
.get("/api/lastmessages").then((res) => {
.get("/api/lastmessages")
.then((res) => {
setMessages(res.data)
})
.catch((err) => {
console.error(err.response)
}
)
}, [])
useEffect(() => {
const id = setInterval(() => {
axios
.get("/api/lastmessages").then((res) => {
setMessages(res.data)
}
)
axios
.get("/api/channels").then((res) => {
setChannels(res.data)
}
)
}, 5000)
return () => { clearInterval(id) }
}, [])
return (
<div>
<h1>Home</h1>
@ -74,7 +97,7 @@ export default function Home() {
</li>
))}
</ul>
<img src="cat.jpg" alt="cat" className="cat"/>
<img src="osaka_arch.png" alt="osaka" className="osaka"/>
</div>
)
}