+ const [user, setUser] = useState(null);
+
+ const checkAuth = async () => {
+ try {
+ const response = await axios.get('/api/user');
+ setUser(response.data);
+ } catch (e) {
+ setUser(null);
+ }
+ };
+
+ const doLogout = async () => {
+ await axios.post('/logout');
+ await checkAuth();
+ };
+
+ useEffect(() => {
+ let timer = null;
+ axios
+ .get('/sanctum/csrf-cookie')
+ .then(() => {
+ checkAuth();
+ timer = setInterval(checkAuth, 15 * 60 * 1000);
+ });
+ return () => {
+ if (timer) clearInterval(timer);
+ };
+ }, []);
+