Skip to content

Commit 789a967

Browse files
committed
feat(admin): add styled buttons and session heartbeat
- Add StyledButtons.jsx component with gradient, copy, danger buttons - Update Settings.jsx to use styled buttons throughout - Improve JWT Key Generator UI with modern styled buttons - Add session heartbeat to Initializer to prevent 401 token expiration - Heartbeat pings /license/status every 4 minutes
1 parent 5599d5c commit 789a967

File tree

3 files changed

+476
-42
lines changed

3 files changed

+476
-42
lines changed

admin/src/components/Initializer.jsx

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,49 @@
1-
import { useEffect } from 'react';
1+
import { useEffect, useRef } from 'react';
2+
import { useFetchClient } from '@strapi/strapi/admin';
3+
import pluginId from '../pluginId';
4+
5+
/**
6+
* Initializer component that sets up the plugin and maintains session
7+
* Includes a heartbeat to keep the admin session alive
8+
*/
9+
const Initializer = ({ setPlugin }) => {
10+
const ref = useRef(setPlugin);
11+
const { get } = useFetchClient();
212

3-
const Initializer = () => {
413
useEffect(() => {
5-
console.log('[magic-sessionmanager] Plugin initialized');
14+
if (ref.current) {
15+
ref.current(pluginId);
16+
}
617
}, []);
718

19+
// Session heartbeat - keeps token alive by making periodic requests
20+
useEffect(() => {
21+
const HEARTBEAT_INTERVAL = 4 * 60 * 1000; // 4 minutes
22+
23+
/**
24+
* Sends a lightweight request to keep the session active
25+
*/
26+
const heartbeat = async () => {
27+
try {
28+
// Use plugin's own license status endpoint as heartbeat (lightweight, authenticated)
29+
await get(`/${pluginId}/license/status`);
30+
} catch (error) {
31+
// Silently ignore errors - this is just a keep-alive
32+
}
33+
};
34+
35+
// Initial heartbeat after 1 minute
36+
const initialTimeout = setTimeout(heartbeat, 60 * 1000);
37+
38+
// Regular heartbeat every 4 minutes
39+
const interval = setInterval(heartbeat, HEARTBEAT_INTERVAL);
40+
41+
return () => {
42+
clearTimeout(initialTimeout);
43+
clearInterval(interval);
44+
};
45+
}, [get]);
46+
847
return null;
948
};
1049

0 commit comments

Comments
 (0)