mirror of
https://github.com/linuxserver/budge.git
synced 2026-03-09 00:08:38 +08:00
added ping to help preserve jwt sessions
This commit is contained in:
parent
6ccf4d2f28
commit
eb795d4e33
@ -10,10 +10,16 @@ import Login from './components/Login'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import AddAccountDialog from './components/AddAccountDialog'
|
||||
import { ThemeProvider, createTheme } from '@mui/material/styles'
|
||||
import useInterval from './utils/useInterval'
|
||||
import API from './api'
|
||||
|
||||
export default function App(props) {
|
||||
const theme = useSelector(state => state.app.theme)
|
||||
|
||||
useInterval(() => {
|
||||
API.ping()
|
||||
}, 1800000)
|
||||
|
||||
const darkTheme = createTheme({
|
||||
palette: {
|
||||
mode: 'dark',
|
||||
|
||||
@ -7,7 +7,7 @@ const axios = Axios.create({
|
||||
|
||||
export default class API {
|
||||
static async ping() {
|
||||
const response = await axios.get('/api/me')
|
||||
const response = await axios.post('/api/ping')
|
||||
|
||||
return response.data.data
|
||||
}
|
||||
|
||||
22
frontend/src/utils/useInterval.js
Normal file
22
frontend/src/utils/useInterval.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
|
||||
export default function (callback, delay) {
|
||||
const savedCallback = useRef()
|
||||
// Remember the last callbac
|
||||
useEffect(() => {
|
||||
savedCallback.current = callback
|
||||
}, [callback])
|
||||
|
||||
// Set up the interval
|
||||
useEffect(() => {
|
||||
function tick() {
|
||||
savedCallback.current()
|
||||
}
|
||||
if (delay !== null) {
|
||||
const id = setInterval(tick, delay)
|
||||
return () => {
|
||||
clearInterval(id)
|
||||
}
|
||||
}
|
||||
}, [callback, delay])
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user