generated from lucien/api-template
add: added an auth middleware to simplify code
This commit is contained in:
parent
c34df6609c
commit
e0efe57f5c
9 changed files with 104 additions and 70 deletions
|
@ -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>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue