@strapi/admin 5.53.0 → 5.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin/src/App.js +1 -1
- package/dist/admin/admin/src/App.js.map +1 -1
- package/dist/admin/admin/src/App.mjs +1 -1
- package/dist/admin/admin/src/App.mjs.map +1 -1
- package/dist/admin/admin/src/components/DismissibleBanner.js +60 -0
- package/dist/admin/admin/src/components/DismissibleBanner.js.map +1 -0
- package/dist/admin/admin/src/components/DismissibleBanner.mjs +58 -0
- package/dist/admin/admin/src/components/DismissibleBanner.mjs.map +1 -0
- package/dist/admin/admin/src/components/Form.js +11 -2
- package/dist/admin/admin/src/components/Form.js.map +1 -1
- package/dist/admin/admin/src/components/Form.mjs +11 -2
- package/dist/admin/admin/src/components/Form.mjs.map +1 -1
- package/dist/admin/admin/src/components/FormInputs/DateTime.js +1 -1
- package/dist/admin/admin/src/components/FormInputs/DateTime.js.map +1 -1
- package/dist/admin/admin/src/components/FormInputs/DateTime.mjs +1 -1
- package/dist/admin/admin/src/components/FormInputs/DateTime.mjs.map +1 -1
- package/dist/admin/admin/src/components/FormInputs/Time.js +1 -1
- package/dist/admin/admin/src/components/FormInputs/Time.js.map +1 -1
- package/dist/admin/admin/src/components/FormInputs/Time.mjs +1 -1
- package/dist/admin/admin/src/components/FormInputs/Time.mjs.map +1 -1
- package/dist/admin/admin/src/components/MainNav/NavUser.js +1 -2
- package/dist/admin/admin/src/components/MainNav/NavUser.js.map +1 -1
- package/dist/admin/admin/src/components/MainNav/NavUser.mjs +1 -2
- package/dist/admin/admin/src/components/MainNav/NavUser.mjs.map +1 -1
- package/dist/admin/admin/src/components/MediaLibraryBanner.js +85 -0
- package/dist/admin/admin/src/components/MediaLibraryBanner.js.map +1 -0
- package/dist/admin/admin/src/components/MediaLibraryBanner.mjs +83 -0
- package/dist/admin/admin/src/components/MediaLibraryBanner.mjs.map +1 -0
- package/dist/admin/admin/src/components/Providers.js +6 -6
- package/dist/admin/admin/src/components/Providers.js.map +1 -1
- package/dist/admin/admin/src/components/Providers.mjs +6 -6
- package/dist/admin/admin/src/components/Providers.mjs.map +1 -1
- package/dist/admin/admin/src/components/UpsellBanner.js +56 -86
- package/dist/admin/admin/src/components/UpsellBanner.js.map +1 -1
- package/dist/admin/admin/src/components/UpsellBanner.mjs +58 -88
- package/dist/admin/admin/src/components/UpsellBanner.mjs.map +1 -1
- package/dist/admin/admin/src/core/store/configure.js +14 -2
- package/dist/admin/admin/src/core/store/configure.js.map +1 -1
- package/dist/admin/admin/src/core/store/configure.mjs +14 -2
- package/dist/admin/admin/src/core/store/configure.mjs.map +1 -1
- package/dist/admin/admin/src/core/store/hooks.mjs +1 -1
- package/dist/admin/admin/src/features/Auth.js +162 -46
- package/dist/admin/admin/src/features/Auth.js.map +1 -1
- package/dist/admin/admin/src/features/Auth.mjs +164 -48
- package/dist/admin/admin/src/features/Auth.mjs.map +1 -1
- package/dist/admin/admin/src/hooks/useRegisterUnsavedChanges.js +19 -0
- package/dist/admin/admin/src/hooks/useRegisterUnsavedChanges.js.map +1 -0
- package/dist/admin/admin/src/hooks/useRegisterUnsavedChanges.mjs +17 -0
- package/dist/admin/admin/src/hooks/useRegisterUnsavedChanges.mjs.map +1 -0
- package/dist/admin/admin/src/hooks/{useIdleSessionLogout.js → useSessionKeepalive.js} +34 -27
- package/dist/admin/admin/src/hooks/useSessionKeepalive.js.map +1 -0
- package/dist/admin/admin/src/hooks/{useIdleSessionLogout.mjs → useSessionKeepalive.mjs} +34 -27
- package/dist/admin/admin/src/hooks/useSessionKeepalive.mjs.map +1 -0
- package/dist/admin/admin/src/layouts/AuthenticatedLayout.js +2 -0
- package/dist/admin/admin/src/layouts/AuthenticatedLayout.js.map +1 -1
- package/dist/admin/admin/src/layouts/AuthenticatedLayout.mjs +2 -0
- package/dist/admin/admin/src/layouts/AuthenticatedLayout.mjs.map +1 -1
- package/dist/admin/admin/src/pages/SessionsPage.js +2 -5
- package/dist/admin/admin/src/pages/SessionsPage.js.map +1 -1
- package/dist/admin/admin/src/pages/SessionsPage.mjs +2 -5
- package/dist/admin/admin/src/pages/SessionsPage.mjs.map +1 -1
- package/dist/admin/admin/src/render.js +5 -0
- package/dist/admin/admin/src/render.js.map +1 -1
- package/dist/admin/admin/src/render.mjs +5 -0
- package/dist/admin/admin/src/render.mjs.map +1 -1
- package/dist/admin/admin/src/translations/en.json.js +12 -0
- package/dist/admin/admin/src/translations/en.json.js.map +1 -1
- package/dist/admin/admin/src/translations/en.json.mjs +12 -0
- package/dist/admin/admin/src/translations/en.json.mjs.map +1 -1
- package/dist/admin/admin/src/utils/baseQuery.js +3 -13
- package/dist/admin/admin/src/utils/baseQuery.js.map +1 -1
- package/dist/admin/admin/src/utils/baseQuery.mjs +3 -13
- package/dist/admin/admin/src/utils/baseQuery.mjs.map +1 -1
- package/dist/admin/admin/src/utils/getFetchClient.js +34 -5
- package/dist/admin/admin/src/utils/getFetchClient.js.map +1 -1
- package/dist/admin/admin/src/utils/getFetchClient.mjs +34 -6
- package/dist/admin/admin/src/utils/getFetchClient.mjs.map +1 -1
- package/dist/admin/admin/src/utils/unsavedChangesRegistry.js +25 -0
- package/dist/admin/admin/src/utils/unsavedChangesRegistry.js.map +1 -0
- package/dist/admin/admin/src/utils/unsavedChangesRegistry.mjs +22 -0
- package/dist/admin/admin/src/utils/unsavedChangesRegistry.mjs.map +1 -0
- package/dist/admin/admin/tests/utils.js +14 -14
- package/dist/admin/admin/tests/utils.js.map +1 -1
- package/dist/admin/admin/tests/utils.mjs +14 -14
- package/dist/admin/admin/tests/utils.mjs.map +1 -1
- package/dist/admin/ee/admin/src/pages/SettingsPage/pages/AuditLogs/utils/getActionTypesDefaultMessages.js +5 -1
- package/dist/admin/ee/admin/src/pages/SettingsPage/pages/AuditLogs/utils/getActionTypesDefaultMessages.js.map +1 -1
- package/dist/admin/ee/admin/src/pages/SettingsPage/pages/AuditLogs/utils/getActionTypesDefaultMessages.mjs +5 -1
- package/dist/admin/ee/admin/src/pages/SettingsPage/pages/AuditLogs/utils/getActionTypesDefaultMessages.mjs.map +1 -1
- package/dist/admin/index.js +1 -0
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/components/DismissibleBanner.d.ts +8 -0
- package/dist/admin/src/components/MediaLibraryBanner.d.ts +2 -0
- package/dist/admin/src/hooks/useRegisterUnsavedChanges.d.ts +6 -0
- package/dist/admin/src/hooks/useSessionKeepalive.d.ts +88 -0
- package/dist/admin/src/utils/getFetchClient.d.ts +14 -6
- package/dist/admin/src/utils/unsavedChangesRegistry.d.ts +11 -0
- package/dist/ee/admin/src/pages/SettingsPage/pages/AuditLogs/utils/getActionTypesDefaultMessages.d.ts +4 -0
- package/dist/shared/contracts/shared.d.ts +1 -0
- package/dist/shared/contracts/shared.d.ts.map +1 -1
- package/package.json +7 -7
- package/dist/admin/admin/src/hooks/useIdleSessionLogout.js.map +0 -1
- package/dist/admin/admin/src/hooks/useIdleSessionLogout.mjs.map +0 -1
- package/dist/admin/src/hooks/useIdleSessionLogout.d.ts +0 -87
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { Dialog } from '@strapi/design-system';
|
|
4
|
+
import { useIntl } from 'react-intl';
|
|
3
5
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
6
|
+
import { ConfirmDialog } from '../components/ConfirmDialog.mjs';
|
|
4
7
|
import { createContext } from '../components/Context.mjs';
|
|
5
8
|
import { useTypedDispatch, useTypedSelector } from '../core/store/hooks.mjs';
|
|
6
9
|
import { useStrapiApp } from './StrapiApp.mjs';
|
|
7
|
-
import { useIdleSessionLogout } from '../hooks/useIdleSessionLogout.mjs';
|
|
8
10
|
import { useQueryParams } from '../hooks/useQueryParams.mjs';
|
|
11
|
+
import { useSessionKeepalive } from '../hooks/useSessionKeepalive.mjs';
|
|
9
12
|
import { logout, setToken, setLocale, login, getStoredToken } from '../reducer.mjs';
|
|
10
13
|
import { adminApi } from '../services/api.mjs';
|
|
11
14
|
import { useGetMeQuery, useGetMyPermissionsQuery, useLoginMutation, useLogoutMutation, useLazyCheckPermissionsQuery } from '../services/auth.mjs';
|
|
12
15
|
import { normalizeAdminLocale } from '../translations/normalizeAdminLocale.mjs';
|
|
13
16
|
import { getOrCreateDeviceId } from '../utils/deviceId.mjs';
|
|
14
|
-
import { attemptTokenRefresh, setOnSessionExpired, setOnTokenUpdate } from '../utils/getFetchClient.mjs';
|
|
17
|
+
import { getFetchClient, attemptTokenRefresh, setOnSessionExpired, resetSessionExpiredNotification, setOnTokenUpdate } from '../utils/getFetchClient.mjs';
|
|
18
|
+
import { hasUnsavedChanges } from '../utils/unsavedChangesRegistry.mjs';
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* ensure the Auth context never exposes a non-function for checkUserHasPermissions.
|
|
@@ -32,7 +36,32 @@ const [Provider, useAuth] = createContext('Auth');
|
|
|
32
36
|
const STORAGE_KEYS = {
|
|
33
37
|
STATUS: 'isLoggedIn'
|
|
34
38
|
};
|
|
39
|
+
const isForcedLogout = (reason)=>reason === 'session-dead';
|
|
40
|
+
/**
|
|
41
|
+
* Copy for the unsaved-changes prompt. A server-confirmed dead session needs to
|
|
42
|
+
* say *why* the dialog appeared, otherwise it reads as the usual navigation
|
|
43
|
+
* blocker and users confirm straight through it.
|
|
44
|
+
*/ const LOGOUT_PROMPTS = {
|
|
45
|
+
voluntary: {
|
|
46
|
+
title: undefined,
|
|
47
|
+
body: {
|
|
48
|
+
id: 'global.prompt.unsaved',
|
|
49
|
+
defaultMessage: 'You have unsaved changes, are you sure you want to leave?'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
'session-dead': {
|
|
53
|
+
title: {
|
|
54
|
+
id: 'app.session.ended.title',
|
|
55
|
+
defaultMessage: 'Session ended'
|
|
56
|
+
},
|
|
57
|
+
body: {
|
|
58
|
+
id: 'app.session.ended.unsaved',
|
|
59
|
+
defaultMessage: "Your session has ended and can't be resumed. Your unsaved changes will be lost when you log out."
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
35
63
|
const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken = false })=>{
|
|
64
|
+
const { formatMessage } = useIntl();
|
|
36
65
|
const dispatch = useTypedDispatch();
|
|
37
66
|
const runRbacMiddleware = useStrapiApp('AuthProvider', (state)=>state.rbac.run);
|
|
38
67
|
const location = useLocation();
|
|
@@ -57,7 +86,46 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
57
86
|
const navigate = useNavigate();
|
|
58
87
|
const [loginMutation] = useLoginMutation();
|
|
59
88
|
const [logoutMutation] = useLogoutMutation();
|
|
60
|
-
const
|
|
89
|
+
const pendingLogoutRef = React.useRef(null);
|
|
90
|
+
const logoutGuardOpenRef = React.useRef(false);
|
|
91
|
+
const logoutGuardReasonRef = React.useRef('voluntary');
|
|
92
|
+
const [isSessionLogoutDialogOpen, setIsSessionLogoutDialogOpen] = React.useState(false);
|
|
93
|
+
const [sessionLogoutReason, setSessionLogoutReason] = React.useState('voluntary');
|
|
94
|
+
/**
|
|
95
|
+
* Prompt before discarding unsaved edits, then run `logoutFn`.
|
|
96
|
+
*
|
|
97
|
+
* - `voluntary`: Cancel leaves the user logged in (server session intact).
|
|
98
|
+
* - `session-dead`: the session is already unusable — Cancel (or dismiss)
|
|
99
|
+
* still runs `logoutFn` so the client cannot keep a stale token. While the
|
|
100
|
+
* dialog is open, a later `session-dead` request upgrades the pending action.
|
|
101
|
+
*/ const runLogoutWithGuard = React.useCallback((logoutFn, reason = 'voluntary')=>{
|
|
102
|
+
if (logoutGuardOpenRef.current) {
|
|
103
|
+
pendingLogoutRef.current = logoutFn;
|
|
104
|
+
if (isForcedLogout(reason)) {
|
|
105
|
+
logoutGuardReasonRef.current = reason;
|
|
106
|
+
setSessionLogoutReason(reason);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!hasUnsavedChanges()) {
|
|
111
|
+
logoutFn();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
logoutGuardOpenRef.current = true;
|
|
115
|
+
logoutGuardReasonRef.current = reason;
|
|
116
|
+
pendingLogoutRef.current = logoutFn;
|
|
117
|
+
setSessionLogoutReason(reason);
|
|
118
|
+
setIsSessionLogoutDialogOpen(true);
|
|
119
|
+
}, []);
|
|
120
|
+
const performGlobalLogout = React.useCallback(()=>{
|
|
121
|
+
void (async ()=>{
|
|
122
|
+
try {
|
|
123
|
+
const { post } = getFetchClient();
|
|
124
|
+
await post('/admin/logout');
|
|
125
|
+
} catch {
|
|
126
|
+
// The session may already be invalid.
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
61
129
|
dispatch(adminApi.util.resetApiState());
|
|
62
130
|
dispatch(logout());
|
|
63
131
|
navigate('/auth/login');
|
|
@@ -65,22 +133,40 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
65
133
|
dispatch,
|
|
66
134
|
navigate
|
|
67
135
|
]);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* shared `isLoggedIn`/`jwtToken` storage keys. Unlike `clearStateAndLogout`,
|
|
71
|
-
* this does not dispatch `logoutAction`, so it does not fire the cross-tab
|
|
72
|
-
* `storage` event that logs every tab out. Used by the speculative idle timer,
|
|
73
|
-
* which fires per-tab at the access token's `exp`: an idle tab must never tear
|
|
74
|
-
* down a session that another tab is still actively using. A genuine logout
|
|
75
|
-
* (user-initiated, or a server-confirmed 401 via `setOnSessionExpired`) still
|
|
76
|
-
* goes through `clearStateAndLogout` and broadcasts to all tabs.
|
|
77
|
-
*/ const clearLocalSessionAndRedirect = React.useCallback(()=>{
|
|
78
|
-
dispatch(adminApi.util.resetApiState());
|
|
79
|
-
dispatch(setToken(null));
|
|
80
|
-
navigate('/auth/login');
|
|
136
|
+
const clearStateAndLogout = React.useCallback(()=>{
|
|
137
|
+
runLogoutWithGuard(performGlobalLogout, 'session-dead');
|
|
81
138
|
}, [
|
|
82
|
-
|
|
83
|
-
|
|
139
|
+
performGlobalLogout,
|
|
140
|
+
runLogoutWithGuard
|
|
141
|
+
]);
|
|
142
|
+
const handleConfirmSessionLogout = React.useCallback(()=>{
|
|
143
|
+
logoutGuardOpenRef.current = false;
|
|
144
|
+
logoutGuardReasonRef.current = 'voluntary';
|
|
145
|
+
setIsSessionLogoutDialogOpen(false);
|
|
146
|
+
setSessionLogoutReason('voluntary');
|
|
147
|
+
const logoutFn = pendingLogoutRef.current;
|
|
148
|
+
pendingLogoutRef.current = null;
|
|
149
|
+
logoutFn?.();
|
|
150
|
+
}, []);
|
|
151
|
+
const handleCancelSessionLogout = React.useCallback(()=>{
|
|
152
|
+
const forced = isForcedLogout(logoutGuardReasonRef.current);
|
|
153
|
+
const logoutFn = pendingLogoutRef.current;
|
|
154
|
+
logoutGuardOpenRef.current = false;
|
|
155
|
+
logoutGuardReasonRef.current = 'voluntary';
|
|
156
|
+
pendingLogoutRef.current = null;
|
|
157
|
+
setIsSessionLogoutDialogOpen(false);
|
|
158
|
+
setSessionLogoutReason('voluntary');
|
|
159
|
+
// Forced paths: session is already dead — dismiss must still clear client state.
|
|
160
|
+
if (forced) {
|
|
161
|
+
logoutFn?.();
|
|
162
|
+
}
|
|
163
|
+
}, []);
|
|
164
|
+
const handleSessionLogoutDialogOpenChange = React.useCallback((open)=>{
|
|
165
|
+
if (!open) {
|
|
166
|
+
handleCancelSessionLogout();
|
|
167
|
+
}
|
|
168
|
+
}, [
|
|
169
|
+
handleCancelSessionLogout
|
|
84
170
|
]);
|
|
85
171
|
const resyncToken = React.useCallback((newToken)=>{
|
|
86
172
|
dispatch(setToken(newToken));
|
|
@@ -89,10 +175,11 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
89
175
|
]);
|
|
90
176
|
/**
|
|
91
177
|
* Track the timestamp of the user's last interaction. This is the activity
|
|
92
|
-
* signal `
|
|
93
|
-
* their session) apart from a genuinely idle one (
|
|
94
|
-
*
|
|
95
|
-
*
|
|
178
|
+
* signal `useSessionKeepalive` uses to tell an active user (silently renew
|
|
179
|
+
* their session) apart from a genuinely idle one (leave the stale access
|
|
180
|
+
* token alone until the next request). Successful API calls don't refresh
|
|
181
|
+
* the short-lived access token on their own, so without this an
|
|
182
|
+
* actively-working user would hit a 401 the moment the token expires.
|
|
96
183
|
*/ const lastActivityRef = React.useRef(Date.now());
|
|
97
184
|
React.useEffect(()=>{
|
|
98
185
|
const markActivity = ()=>{
|
|
@@ -118,7 +205,7 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
118
205
|
const getLastActivityAt = React.useCallback(()=>lastActivityRef.current, []);
|
|
119
206
|
/**
|
|
120
207
|
* Silently rotate the refresh token and mint a new access token. Returns
|
|
121
|
-
* `true` on success (the resulting `setToken` re-arms the
|
|
208
|
+
* `true` on success (the resulting `setToken` re-arms the renew timer) and
|
|
122
209
|
* `false` when the server rejects it (session genuinely over).
|
|
123
210
|
*/ const renewSession = React.useCallback(async ()=>{
|
|
124
211
|
try {
|
|
@@ -167,15 +254,15 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
167
254
|
clearStateAndLogout
|
|
168
255
|
]);
|
|
169
256
|
/**
|
|
170
|
-
* Session
|
|
171
|
-
* then either (1) re-syncs from a token another tab refreshed, (2)
|
|
172
|
-
* renews when the user has been active, or (3)
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
|
|
257
|
+
* Session keepalive around access-token expiry. The timer fires per-tab; the
|
|
258
|
+
* hook then either (1) re-syncs from a token another tab refreshed, (2)
|
|
259
|
+
* silently renews when the user has been active, or (3) does nothing when
|
|
260
|
+
* idle — leaving the stale access token in place so unsaved form state
|
|
261
|
+
* survives until the next request refreshes it. A server-confirmed dead
|
|
262
|
+
* session (renewal rejected) broadcasts globally via `onSessionDead`. See
|
|
263
|
+
* `useSessionKeepalive` for the full rationale.
|
|
264
|
+
*/ useSessionKeepalive({
|
|
177
265
|
token,
|
|
178
|
-
onExpired: clearLocalSessionAndRedirect,
|
|
179
266
|
onSessionDead: clearStateAndLogout,
|
|
180
267
|
getStoredToken,
|
|
181
268
|
onResync: resyncToken,
|
|
@@ -207,6 +294,7 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
207
294
|
* because if something fails, it will throw an error.
|
|
208
295
|
*/ if ('data' in res) {
|
|
209
296
|
const { token } = res.data;
|
|
297
|
+
resetSessionExpiredNotification();
|
|
210
298
|
dispatch(login({
|
|
211
299
|
token,
|
|
212
300
|
persist: rememberMe
|
|
@@ -217,14 +305,26 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
217
305
|
dispatch,
|
|
218
306
|
loginMutation
|
|
219
307
|
]);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Explicit user logout. Confirm unsaved changes *before* `logoutMutation` so
|
|
310
|
+
* Cancel leaves the server session and client token intact.
|
|
311
|
+
*/ const logout$1 = React.useCallback(async ()=>{
|
|
312
|
+
runLogoutWithGuard(()=>{
|
|
313
|
+
void (async ()=>{
|
|
314
|
+
try {
|
|
315
|
+
await logoutMutation({
|
|
316
|
+
deviceId: getOrCreateDeviceId()
|
|
317
|
+
});
|
|
318
|
+
} catch {
|
|
319
|
+
// The session may already be invalid.
|
|
320
|
+
}
|
|
321
|
+
performGlobalLogout();
|
|
322
|
+
})();
|
|
223
323
|
});
|
|
224
|
-
clearStateAndLogout();
|
|
225
324
|
}, [
|
|
226
|
-
|
|
227
|
-
|
|
325
|
+
logoutMutation,
|
|
326
|
+
performGlobalLogout,
|
|
327
|
+
runLogoutWithGuard
|
|
228
328
|
]);
|
|
229
329
|
const refetchPermissions = React.useCallback(async ()=>{
|
|
230
330
|
if (!isUninitialized) {
|
|
@@ -292,16 +392,32 @@ const AuthProvider = ({ children, _defaultPermissions = [], _disableRenewToken =
|
|
|
292
392
|
userPermissions
|
|
293
393
|
]);
|
|
294
394
|
const isLoading = isLoadingUser || isLoadingPermissions;
|
|
295
|
-
return /*#__PURE__*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
395
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
396
|
+
children: [
|
|
397
|
+
/*#__PURE__*/ jsx(Provider, {
|
|
398
|
+
token: token,
|
|
399
|
+
user: user,
|
|
400
|
+
login: login$1,
|
|
401
|
+
logout: logout$1,
|
|
402
|
+
permissions: userPermissions,
|
|
403
|
+
checkUserHasPermissions: checkUserHasPermissions ?? NOOP_CHECK_USER_HAS_PERMISSIONS,
|
|
404
|
+
refetchPermissions: refetchPermissions,
|
|
405
|
+
isLoading: isLoading,
|
|
406
|
+
children: children
|
|
407
|
+
}),
|
|
408
|
+
/*#__PURE__*/ jsx(Dialog.Root, {
|
|
409
|
+
open: isSessionLogoutDialogOpen,
|
|
410
|
+
onOpenChange: handleSessionLogoutDialogOpenChange,
|
|
411
|
+
children: /*#__PURE__*/ jsx(ConfirmDialog, {
|
|
412
|
+
onConfirm: handleConfirmSessionLogout,
|
|
413
|
+
onCancel: handleCancelSessionLogout,
|
|
414
|
+
title: LOGOUT_PROMPTS[sessionLogoutReason].title ? formatMessage(LOGOUT_PROMPTS[sessionLogoutReason].title) : undefined,
|
|
415
|
+
// Forced session-dead: no Cancel that pretends the session is still valid.
|
|
416
|
+
startAction: isForcedLogout(sessionLogoutReason) ? /*#__PURE__*/ jsx(Fragment, {}) : undefined,
|
|
417
|
+
children: formatMessage(LOGOUT_PROMPTS[sessionLogoutReason].body)
|
|
418
|
+
})
|
|
419
|
+
})
|
|
420
|
+
]
|
|
305
421
|
});
|
|
306
422
|
};
|
|
307
423
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.mjs","sources":["../../../../../admin/src/features/Auth.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { useLocation, useNavigate } from 'react-router-dom';\n\nimport { Login } from '../../../shared/contracts/authentication';\nimport { createContext } from '../components/Context';\nimport { useTypedDispatch, useTypedSelector } from '../core/store/hooks';\nimport { useStrapiApp } from '../features/StrapiApp';\nimport { useIdleSessionLogout } from '../hooks/useIdleSessionLogout';\nimport { useQueryParams } from '../hooks/useQueryParams';\nimport {\n getStoredToken,\n login as loginAction,\n logout as logoutAction,\n setLocale,\n setToken,\n} from '../reducer';\nimport { adminApi } from '../services/api';\nimport {\n useGetMeQuery,\n useGetMyPermissionsQuery,\n useLazyCheckPermissionsQuery,\n useLoginMutation,\n useLogoutMutation,\n} from '../services/auth';\nimport { normalizeAdminLocale } from '../translations/normalizeAdminLocale';\nimport { getOrCreateDeviceId } from '../utils/deviceId';\nimport {\n attemptTokenRefresh,\n setOnSessionExpired,\n setOnTokenUpdate,\n} from '../utils/getFetchClient';\n\nimport type {\n Permission as PermissionContract,\n SanitizedAdminUser,\n} from '../../../shared/contracts/shared';\n\ninterface Permission\n extends Pick<PermissionContract, 'action' | 'subject'>,\n Partial<Omit<PermissionContract, 'action' | 'subject'>> {}\n\ninterface User\n extends Pick<SanitizedAdminUser, 'email' | 'firstname' | 'lastname' | 'username' | 'roles'>,\n Partial<Omit<SanitizedAdminUser, 'email' | 'firstname' | 'lastname' | 'username' | 'roles'>> {}\n\ninterface AuthContextValue {\n login: (\n body: Login.Request['body'] & { rememberMe: boolean }\n ) => Promise<Awaited<ReturnType<ReturnType<typeof useLoginMutation>[0]>>>;\n logout: () => Promise<void>;\n /**\n * @alpha\n * @description given a list of permissions, this function checks\n * those against the current user's permissions or those passed as\n * the second argument, if the user has those permissions the complete\n * permission object form the API is returned. Therefore, if the list is\n * empty, the user does not have any of those permissions.\n */\n checkUserHasPermissions: (\n permissions?: Array<Pick<Permission, 'action'> & Partial<Omit<Permission, 'action'>>>,\n passedPermissions?: Permission[],\n rawQueryContext?: string\n ) => Promise<Permission[]>;\n isLoading: boolean;\n permissions: Permission[];\n refetchPermissions: () => Promise<void>;\n token: string | null;\n user?: User;\n}\n\n/**\n * ensure the Auth context never exposes a non-function for checkUserHasPermissions.\n * When this is undefined (e.g. context timing in production builds), consumers would throw\n * \"p is not a function\" / \"checkUserHasPermissions is not a function\". By always passing\n * a function here, all current and future consumers are protected without per-call-site guards.\n *\n * When would the fallback run? Only if the real checkUserHasPermissions were ever undefined\n * when we pass to the Provider (e.g. a rare timing/build edge case). In normal runs it is\n * always defined (useCallback), so the real function is passed and behavior is unchanged.\n *\n * If the fallback ever did run: it returns [] so consumers (which use .length > 0) treat it\n * as \"no permission\" for that render—under-permissive. On the next AuthProvider re-render we\n * pass the real function again, so the context updates and the view corrects quickly.\n * @see https://github.com/strapi/strapi/issues/24384\n */\nconst NOOP_CHECK_USER_HAS_PERMISSIONS: AuthContextValue['checkUserHasPermissions'] = async () => [];\n\nconst [Provider, useAuth] = createContext<AuthContextValue>('Auth');\n\ninterface AuthProviderProps {\n children: React.ReactNode;\n /**\n * @internal could be removed at any time.\n */\n _defaultPermissions?: Permission[];\n\n // NOTE: this is used for testing purposed only\n _disableRenewToken?: boolean;\n}\n\nconst STORAGE_KEYS = {\n TOKEN: 'jwtToken',\n STATUS: 'isLoggedIn',\n};\n\nconst AuthProvider = ({\n children,\n _defaultPermissions = [],\n _disableRenewToken = false,\n}: AuthProviderProps) => {\n const dispatch = useTypedDispatch();\n const runRbacMiddleware = useStrapiApp('AuthProvider', (state) => state.rbac.run);\n const location = useLocation();\n const [{ rawQuery }] = useQueryParams();\n\n const locationRef = React.useRef(location);\n\n // Update ref without causing re-render\n React.useEffect(() => {\n locationRef.current = location;\n }, [location]);\n\n const token = useTypedSelector((state) => state.admin_app.token ?? null);\n\n const { data: user, isLoading: isLoadingUser } = useGetMeQuery(undefined, {\n /**\n * If there's no token, we don't try to fetch\n * the user data because it will fail.\n */\n skip: !token,\n });\n\n const {\n data: userPermissions = _defaultPermissions,\n refetch,\n isUninitialized,\n isLoading: isLoadingPermissions,\n } = useGetMyPermissionsQuery(undefined, {\n skip: !token,\n });\n\n const navigate = useNavigate();\n\n const [loginMutation] = useLoginMutation();\n const [logoutMutation] = useLogoutMutation();\n\n const clearStateAndLogout = React.useCallback(() => {\n dispatch(adminApi.util.resetApiState());\n dispatch(logoutAction());\n navigate('/auth/login');\n }, [dispatch, navigate]);\n\n /**\n * Clear *only this tab's* session and redirect to login, without removing the\n * shared `isLoggedIn`/`jwtToken` storage keys. Unlike `clearStateAndLogout`,\n * this does not dispatch `logoutAction`, so it does not fire the cross-tab\n * `storage` event that logs every tab out. Used by the speculative idle timer,\n * which fires per-tab at the access token's `exp`: an idle tab must never tear\n * down a session that another tab is still actively using. A genuine logout\n * (user-initiated, or a server-confirmed 401 via `setOnSessionExpired`) still\n * goes through `clearStateAndLogout` and broadcasts to all tabs.\n */\n const clearLocalSessionAndRedirect = React.useCallback(() => {\n dispatch(adminApi.util.resetApiState());\n dispatch(setToken(null));\n navigate('/auth/login');\n }, [dispatch, navigate]);\n\n const resyncToken = React.useCallback(\n (newToken: string) => {\n dispatch(setToken(newToken));\n },\n [dispatch]\n );\n\n /**\n * Track the timestamp of the user's last interaction. This is the activity\n * signal `useIdleSessionLogout` uses to tell an active user (silently renew\n * their session) apart from a genuinely idle one (log out). Successful API\n * calls don't refresh the short-lived access token on their own, so without\n * this an actively-working user is logged out the moment the token expires.\n */\n const lastActivityRef = React.useRef(Date.now());\n React.useEffect(() => {\n const markActivity = () => {\n lastActivityRef.current = Date.now();\n };\n const events = ['pointerdown', 'keydown', 'click', 'scroll', 'touchstart'];\n events.forEach((event) =>\n window.addEventListener(event, markActivity, { passive: true, capture: true })\n );\n\n return () => {\n events.forEach((event) => window.removeEventListener(event, markActivity, { capture: true }));\n };\n }, []);\n const getLastActivityAt = React.useCallback(() => lastActivityRef.current, []);\n\n /**\n * Silently rotate the refresh token and mint a new access token. Returns\n * `true` on success (the resulting `setToken` re-arms the idle timer) and\n * `false` when the server rejects it (session genuinely over).\n */\n const renewSession = React.useCallback(async () => {\n try {\n await attemptTokenRefresh();\n return true;\n } catch {\n return false;\n }\n }, []);\n\n React.useEffect(() => {\n if (user) {\n if (user.preferedLanguage) {\n dispatch(setLocale(normalizeAdminLocale(user.preferedLanguage)));\n }\n }\n }, [dispatch, user]);\n\n /**\n * Register a callback to update Redux state when the token is refreshed.\n * This ensures the app state stays in sync with the token stored in localStorage/cookies.\n */\n React.useEffect(() => {\n setOnTokenUpdate((newToken) => {\n dispatch(setToken(newToken));\n });\n\n return () => {\n setOnTokenUpdate(null);\n };\n }, [dispatch]);\n\n /**\n * Register the session-expired handler that the fetch layer / RTK baseQuery\n * call when the server rejects the refresh token. This is what redirects\n * the active tab to /auth/login on a 401, instead of leaving the user on\n * a stale page until they click something.\n */\n React.useEffect(() => {\n setOnSessionExpired(() => {\n clearStateAndLogout();\n });\n\n return () => {\n setOnSessionExpired(null);\n };\n }, [clearStateAndLogout]);\n\n /**\n * Session lifecycle at access-token expiry. The timer fires per-tab; the hook\n * then either (1) re-syncs from a token another tab refreshed, (2) silently\n * renews when the user has been active, or (3) logs out. Idle logout is local\n * so an idle tab can't force-logout an actively-used one; a server-confirmed\n * dead session (renewal rejected) broadcasts globally. See\n * `useIdleSessionLogout` for the full rationale.\n */\n useIdleSessionLogout({\n token,\n onExpired: clearLocalSessionAndRedirect,\n onSessionDead: clearStateAndLogout,\n getStoredToken,\n onResync: resyncToken,\n getLastActivityAt,\n renewSession,\n disabled: _disableRenewToken,\n });\n\n React.useEffect(() => {\n /**\n * This will log a user out of all tabs if they log out in one tab.\n */\n const handleUserStorageChange = (event: StorageEvent) => {\n if (event.key === STORAGE_KEYS.STATUS && event.newValue === null) {\n clearStateAndLogout();\n }\n };\n\n window.addEventListener('storage', handleUserStorageChange);\n\n return () => {\n window.removeEventListener('storage', handleUserStorageChange);\n };\n });\n\n const login = React.useCallback<AuthContextValue['login']>(\n async ({ rememberMe, ...body }) => {\n const res = await loginMutation({ ...body, deviceId: getOrCreateDeviceId(), rememberMe });\n\n /**\n * There will always be a `data` key in the response\n * because if something fails, it will throw an error.\n */\n if ('data' in res) {\n const { token } = res.data;\n\n dispatch(\n loginAction({\n token,\n persist: rememberMe,\n })\n );\n }\n\n return res;\n },\n [dispatch, loginMutation]\n );\n\n const logout = React.useCallback(async () => {\n await logoutMutation({ deviceId: getOrCreateDeviceId() });\n clearStateAndLogout();\n }, [clearStateAndLogout, logoutMutation]);\n\n const refetchPermissions = React.useCallback(async () => {\n if (!isUninitialized) {\n await refetch();\n }\n }, [isUninitialized, refetch]);\n\n const [checkPermissions] = useLazyCheckPermissionsQuery();\n const checkUserHasPermissions: AuthContextValue['checkUserHasPermissions'] = React.useCallback(\n async (\n permissions,\n passedPermissions,\n // TODO:\n // Here we have parameterised checkUserHasPermissions in order to pass\n // query context from elsewhere in the application.\n // See packages/core/content-manager/admin/src/features/DocumentRBAC.tsx\n\n // This is in order to calculate permissions on accurate query params.\n // We should be able to rely on the query params in this provider\n // If we need to pass additional context to the RBAC middleware\n // we should define a better context type.\n rawQueryContext\n ) => {\n /**\n * If there's no permissions to check, then we allow it to\n * pass to preserve existing behaviours.\n *\n * TODO: should we review this? it feels more dangerous than useful.\n */\n if (!permissions || permissions.length === 0) {\n return [{ action: '', subject: '' }];\n }\n\n /**\n * Given the provided permissions, return the permissions from either passedPermissions\n * or userPermissions as this is expected to be the full permission entity.\n */\n const actualUserPermissions = passedPermissions ?? userPermissions;\n\n const matchingPermissions = actualUserPermissions.filter(\n (permission) =>\n permissions.findIndex(\n (perm) =>\n perm.action === permission.action &&\n // Only check the subject if it's provided\n (perm.subject == undefined || perm.subject === permission.subject)\n ) >= 0\n );\n\n const middlewaredPermissions = await runRbacMiddleware(\n {\n user,\n permissions: userPermissions,\n pathname: locationRef.current.pathname,\n search: (rawQueryContext || rawQuery).split('?')[1] ?? '',\n },\n matchingPermissions\n );\n\n const shouldCheckConditions = middlewaredPermissions.some(\n (perm) => Array.isArray(perm.conditions) && perm.conditions.length > 0\n );\n\n if (!shouldCheckConditions) {\n return middlewaredPermissions;\n }\n\n const { data, error } = await checkPermissions({\n permissions: middlewaredPermissions.map((perm) => ({\n action: perm.action,\n subject: perm.subject,\n })),\n });\n\n if (error) {\n throw error;\n } else {\n return middlewaredPermissions.filter((_, index) => data?.data[index] === true);\n }\n },\n [checkPermissions, rawQuery, runRbacMiddleware, user, userPermissions]\n );\n\n const isLoading = isLoadingUser || isLoadingPermissions;\n\n return (\n <Provider\n token={token}\n user={user}\n login={login}\n logout={logout}\n permissions={userPermissions}\n checkUserHasPermissions={checkUserHasPermissions ?? NOOP_CHECK_USER_HAS_PERMISSIONS}\n refetchPermissions={refetchPermissions}\n isLoading={isLoading}\n >\n {children}\n </Provider>\n );\n};\n\nexport { AuthProvider, useAuth, STORAGE_KEYS };\nexport type { AuthContextValue, Permission, User };\n"],"names":["NOOP_CHECK_USER_HAS_PERMISSIONS","Provider","useAuth","createContext","STORAGE_KEYS","STATUS","AuthProvider","children","_defaultPermissions","_disableRenewToken","dispatch","useTypedDispatch","runRbacMiddleware","useStrapiApp","state","rbac","run","location","useLocation","rawQuery","useQueryParams","locationRef","React","useRef","useEffect","current","token","useTypedSelector","admin_app","data","user","isLoading","isLoadingUser","useGetMeQuery","undefined","skip","userPermissions","refetch","isUninitialized","isLoadingPermissions","useGetMyPermissionsQuery","navigate","useNavigate","loginMutation","useLoginMutation","logoutMutation","useLogoutMutation","clearStateAndLogout","useCallback","adminApi","util","resetApiState","logoutAction","clearLocalSessionAndRedirect","setToken","resyncToken","newToken","lastActivityRef","Date","now","markActivity","events","forEach","event","window","addEventListener","passive","capture","removeEventListener","getLastActivityAt","renewSession","attemptTokenRefresh","preferedLanguage","setLocale","normalizeAdminLocale","setOnTokenUpdate","setOnSessionExpired","useIdleSessionLogout","onExpired","onSessionDead","getStoredToken","onResync","disabled","handleUserStorageChange","key","newValue","login","rememberMe","body","res","deviceId","getOrCreateDeviceId","loginAction","persist","logout","refetchPermissions","checkPermissions","useLazyCheckPermissionsQuery","checkUserHasPermissions","permissions","passedPermissions","rawQueryContext","length","action","subject","actualUserPermissions","matchingPermissions","filter","permission","findIndex","perm","middlewaredPermissions","pathname","search","split","shouldCheckConditions","some","Array","isArray","conditions","error","map","_","index","_jsx"],"mappings":";;;;;;;;;;;;;;;AAuEA;;;;;;;;;;;;;;IAeA,MAAMA,+BAAAA,GAA+E,UAAY,EAAE;AAEnG,MAAM,CAACC,QAAAA,EAAUC,OAAAA,CAAQ,GAAGC,aAAAA,CAAgC,MAAA;AAa5D,MAAMC,YAAAA,GAAe;IAEnBC,MAAAA,EAAQ;AACV;AAEA,MAAMC,YAAAA,GAAe,CAAC,EACpBC,QAAQ,EACRC,sBAAsB,EAAE,EACxBC,kBAAAA,GAAqB,KAAK,EACR,GAAA;AAClB,IAAA,MAAMC,QAAAA,GAAWC,gBAAAA,EAAAA;IACjB,MAAMC,iBAAAA,GAAoBC,aAAa,cAAA,EAAgB,CAACC,QAAUA,KAAAA,CAAMC,IAAI,CAACC,GAAG,CAAA;AAChF,IAAA,MAAMC,QAAAA,GAAWC,WAAAA,EAAAA;AACjB,IAAA,MAAM,CAAC,EAAEC,QAAQ,EAAE,CAAC,GAAGC,cAAAA,EAAAA;IAEvB,MAAMC,WAAAA,GAAcC,KAAAA,CAAMC,MAAM,CAACN,QAAAA,CAAAA;;AAGjCK,IAAAA,KAAAA,CAAME,SAAS,CAAC,IAAA;AACdH,QAAAA,WAAAA,CAAYI,OAAO,GAAGR,QAAAA;IACxB,CAAA,EAAG;AAACA,QAAAA;AAAS,KAAA,CAAA;IAEb,MAAMS,KAAAA,GAAQC,iBAAiB,CAACb,KAAAA,GAAUA,MAAMc,SAAS,CAACF,KAAK,IAAI,IAAA,CAAA;IAEnE,MAAM,EAAEG,MAAMC,IAAI,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":["import * as React from 'react';\n\nimport { Dialog } from '@strapi/design-system';\nimport { useIntl, type MessageDescriptor } from 'react-intl';\nimport { useLocation, useNavigate } from 'react-router-dom';\n\nimport { Login } from '../../../shared/contracts/authentication';\nimport { ConfirmDialog } from '../components/ConfirmDialog';\nimport { createContext } from '../components/Context';\nimport { useTypedDispatch, useTypedSelector } from '../core/store/hooks';\nimport { useStrapiApp } from '../features/StrapiApp';\nimport { useQueryParams } from '../hooks/useQueryParams';\nimport { useSessionKeepalive } from '../hooks/useSessionKeepalive';\nimport {\n getStoredToken,\n login as loginAction,\n logout as logoutAction,\n setLocale,\n setToken,\n} from '../reducer';\nimport { adminApi } from '../services/api';\nimport {\n useGetMeQuery,\n useGetMyPermissionsQuery,\n useLazyCheckPermissionsQuery,\n useLoginMutation,\n useLogoutMutation,\n} from '../services/auth';\nimport { normalizeAdminLocale } from '../translations/normalizeAdminLocale';\nimport { getOrCreateDeviceId } from '../utils/deviceId';\nimport {\n attemptTokenRefresh,\n getFetchClient,\n resetSessionExpiredNotification,\n setOnSessionExpired,\n setOnTokenUpdate,\n} from '../utils/getFetchClient';\nimport { hasUnsavedChanges } from '../utils/unsavedChangesRegistry';\n\nimport type {\n Permission as PermissionContract,\n SanitizedAdminUser,\n} from '../../../shared/contracts/shared';\n\ninterface Permission\n extends Pick<PermissionContract, 'action' | 'subject'>,\n Partial<Omit<PermissionContract, 'action' | 'subject'>> {}\n\ninterface User\n extends Pick<SanitizedAdminUser, 'email' | 'firstname' | 'lastname' | 'username' | 'roles'>,\n Partial<Omit<SanitizedAdminUser, 'email' | 'firstname' | 'lastname' | 'username' | 'roles'>> {}\n\ninterface AuthContextValue {\n login: (\n body: Login.Request['body'] & { rememberMe: boolean }\n ) => Promise<Awaited<ReturnType<ReturnType<typeof useLoginMutation>[0]>>>;\n logout: () => Promise<void>;\n /**\n * @alpha\n * @description given a list of permissions, this function checks\n * those against the current user's permissions or those passed as\n * the second argument, if the user has those permissions the complete\n * permission object form the API is returned. Therefore, if the list is\n * empty, the user does not have any of those permissions.\n */\n checkUserHasPermissions: (\n permissions?: Array<Pick<Permission, 'action'> & Partial<Omit<Permission, 'action'>>>,\n passedPermissions?: Permission[],\n rawQueryContext?: string\n ) => Promise<Permission[]>;\n isLoading: boolean;\n permissions: Permission[];\n refetchPermissions: () => Promise<void>;\n token: string | null;\n user?: User;\n}\n\n/**\n * ensure the Auth context never exposes a non-function for checkUserHasPermissions.\n * When this is undefined (e.g. context timing in production builds), consumers would throw\n * \"p is not a function\" / \"checkUserHasPermissions is not a function\". By always passing\n * a function here, all current and future consumers are protected without per-call-site guards.\n *\n * When would the fallback run? Only if the real checkUserHasPermissions were ever undefined\n * when we pass to the Provider (e.g. a rare timing/build edge case). In normal runs it is\n * always defined (useCallback), so the real function is passed and behavior is unchanged.\n *\n * If the fallback ever did run: it returns [] so consumers (which use .length > 0) treat it\n * as \"no permission\" for that render—under-permissive. On the next AuthProvider re-render we\n * pass the real function again, so the context updates and the view corrects quickly.\n * @see https://github.com/strapi/strapi/issues/24384\n */\nconst NOOP_CHECK_USER_HAS_PERMISSIONS: AuthContextValue['checkUserHasPermissions'] = async () => [];\n\nconst [Provider, useAuth] = createContext<AuthContextValue>('Auth');\n\ninterface AuthProviderProps {\n children: React.ReactNode;\n /**\n * @internal could be removed at any time.\n */\n _defaultPermissions?: Permission[];\n\n // NOTE: this is used for testing purposed only\n _disableRenewToken?: boolean;\n}\n\nconst STORAGE_KEYS = {\n TOKEN: 'jwtToken',\n STATUS: 'isLoggedIn',\n};\n\n/**\n * Why the session is ending.\n * - `voluntary`: explicit user logout — cancelable when there are unsaved edits.\n * - `session-dead`: server rejected the refresh (idle/max session window elapsed)\n * — forced; Cancel / dismiss still clears client state.\n *\n * Short-lived access-token expiry is NOT a logout reason: idle tabs leave the\n * stale token in place and the next request refreshes (or hits session-dead).\n */\ntype LogoutReason = 'voluntary' | 'session-dead';\n\nconst isForcedLogout = (reason: LogoutReason) => reason === 'session-dead';\n\n/**\n * Copy for the unsaved-changes prompt. A server-confirmed dead session needs to\n * say *why* the dialog appeared, otherwise it reads as the usual navigation\n * blocker and users confirm straight through it.\n */\nconst LOGOUT_PROMPTS = {\n voluntary: {\n title: undefined,\n body: {\n id: 'global.prompt.unsaved',\n defaultMessage: 'You have unsaved changes, are you sure you want to leave?',\n },\n },\n 'session-dead': {\n title: {\n id: 'app.session.ended.title',\n defaultMessage: 'Session ended',\n },\n body: {\n id: 'app.session.ended.unsaved',\n defaultMessage:\n \"Your session has ended and can't be resumed. Your unsaved changes will be lost when you log out.\",\n },\n },\n} satisfies Record<LogoutReason, { title?: MessageDescriptor; body: MessageDescriptor }>;\n\nconst AuthProvider = ({\n children,\n _defaultPermissions = [],\n _disableRenewToken = false,\n}: AuthProviderProps) => {\n const { formatMessage } = useIntl();\n const dispatch = useTypedDispatch();\n const runRbacMiddleware = useStrapiApp('AuthProvider', (state) => state.rbac.run);\n const location = useLocation();\n const [{ rawQuery }] = useQueryParams();\n\n const locationRef = React.useRef(location);\n\n // Update ref without causing re-render\n React.useEffect(() => {\n locationRef.current = location;\n }, [location]);\n\n const token = useTypedSelector((state) => state.admin_app.token ?? null);\n\n const { data: user, isLoading: isLoadingUser } = useGetMeQuery(undefined, {\n /**\n * If there's no token, we don't try to fetch\n * the user data because it will fail.\n */\n skip: !token,\n });\n\n const {\n data: userPermissions = _defaultPermissions,\n refetch,\n isUninitialized,\n isLoading: isLoadingPermissions,\n } = useGetMyPermissionsQuery(undefined, {\n skip: !token,\n });\n\n const navigate = useNavigate();\n\n const [loginMutation] = useLoginMutation();\n const [logoutMutation] = useLogoutMutation();\n\n const pendingLogoutRef = React.useRef<(() => void) | null>(null);\n const logoutGuardOpenRef = React.useRef(false);\n const logoutGuardReasonRef = React.useRef<LogoutReason>('voluntary');\n const [isSessionLogoutDialogOpen, setIsSessionLogoutDialogOpen] = React.useState(false);\n const [sessionLogoutReason, setSessionLogoutReason] = React.useState<LogoutReason>('voluntary');\n\n /**\n * Prompt before discarding unsaved edits, then run `logoutFn`.\n *\n * - `voluntary`: Cancel leaves the user logged in (server session intact).\n * - `session-dead`: the session is already unusable — Cancel (or dismiss)\n * still runs `logoutFn` so the client cannot keep a stale token. While the\n * dialog is open, a later `session-dead` request upgrades the pending action.\n */\n const runLogoutWithGuard = React.useCallback(\n (logoutFn: () => void, reason: LogoutReason = 'voluntary') => {\n if (logoutGuardOpenRef.current) {\n pendingLogoutRef.current = logoutFn;\n if (isForcedLogout(reason)) {\n logoutGuardReasonRef.current = reason;\n setSessionLogoutReason(reason);\n }\n return;\n }\n\n if (!hasUnsavedChanges()) {\n logoutFn();\n return;\n }\n\n logoutGuardOpenRef.current = true;\n logoutGuardReasonRef.current = reason;\n pendingLogoutRef.current = logoutFn;\n setSessionLogoutReason(reason);\n setIsSessionLogoutDialogOpen(true);\n },\n []\n );\n\n const performGlobalLogout = React.useCallback(() => {\n void (async () => {\n try {\n const { post } = getFetchClient();\n await post('/admin/logout');\n } catch {\n // The session may already be invalid.\n }\n })();\n\n dispatch(adminApi.util.resetApiState());\n dispatch(logoutAction());\n navigate('/auth/login');\n }, [dispatch, navigate]);\n\n const clearStateAndLogout = React.useCallback(() => {\n runLogoutWithGuard(performGlobalLogout, 'session-dead');\n }, [performGlobalLogout, runLogoutWithGuard]);\n\n const handleConfirmSessionLogout = React.useCallback(() => {\n logoutGuardOpenRef.current = false;\n logoutGuardReasonRef.current = 'voluntary';\n setIsSessionLogoutDialogOpen(false);\n setSessionLogoutReason('voluntary');\n const logoutFn = pendingLogoutRef.current;\n pendingLogoutRef.current = null;\n logoutFn?.();\n }, []);\n\n const handleCancelSessionLogout = React.useCallback(() => {\n const forced = isForcedLogout(logoutGuardReasonRef.current);\n const logoutFn = pendingLogoutRef.current;\n logoutGuardOpenRef.current = false;\n logoutGuardReasonRef.current = 'voluntary';\n pendingLogoutRef.current = null;\n setIsSessionLogoutDialogOpen(false);\n setSessionLogoutReason('voluntary');\n // Forced paths: session is already dead — dismiss must still clear client state.\n if (forced) {\n logoutFn?.();\n }\n }, []);\n\n const handleSessionLogoutDialogOpenChange = React.useCallback(\n (open: boolean) => {\n if (!open) {\n handleCancelSessionLogout();\n }\n },\n [handleCancelSessionLogout]\n );\n\n const resyncToken = React.useCallback(\n (newToken: string) => {\n dispatch(setToken(newToken));\n },\n [dispatch]\n );\n\n /**\n * Track the timestamp of the user's last interaction. This is the activity\n * signal `useSessionKeepalive` uses to tell an active user (silently renew\n * their session) apart from a genuinely idle one (leave the stale access\n * token alone until the next request). Successful API calls don't refresh\n * the short-lived access token on their own, so without this an\n * actively-working user would hit a 401 the moment the token expires.\n */\n const lastActivityRef = React.useRef(Date.now());\n React.useEffect(() => {\n const markActivity = () => {\n lastActivityRef.current = Date.now();\n };\n const events = ['pointerdown', 'keydown', 'click', 'scroll', 'touchstart'];\n events.forEach((event) =>\n window.addEventListener(event, markActivity, { passive: true, capture: true })\n );\n\n return () => {\n events.forEach((event) => window.removeEventListener(event, markActivity, { capture: true }));\n };\n }, []);\n const getLastActivityAt = React.useCallback(() => lastActivityRef.current, []);\n\n /**\n * Silently rotate the refresh token and mint a new access token. Returns\n * `true` on success (the resulting `setToken` re-arms the renew timer) and\n * `false` when the server rejects it (session genuinely over).\n */\n const renewSession = React.useCallback(async () => {\n try {\n await attemptTokenRefresh();\n return true;\n } catch {\n return false;\n }\n }, []);\n\n React.useEffect(() => {\n if (user) {\n if (user.preferedLanguage) {\n dispatch(setLocale(normalizeAdminLocale(user.preferedLanguage)));\n }\n }\n }, [dispatch, user]);\n\n /**\n * Register a callback to update Redux state when the token is refreshed.\n * This ensures the app state stays in sync with the token stored in localStorage/cookies.\n */\n React.useEffect(() => {\n setOnTokenUpdate((newToken) => {\n dispatch(setToken(newToken));\n });\n\n return () => {\n setOnTokenUpdate(null);\n };\n }, [dispatch]);\n\n /**\n * Register the session-expired handler that the fetch layer / RTK baseQuery\n * call when the server rejects the refresh token. This is what redirects\n * the active tab to /auth/login on a 401, instead of leaving the user on\n * a stale page until they click something.\n */\n React.useEffect(() => {\n setOnSessionExpired(() => {\n clearStateAndLogout();\n });\n\n return () => {\n setOnSessionExpired(null);\n };\n }, [clearStateAndLogout]);\n\n /**\n * Session keepalive around access-token expiry. The timer fires per-tab; the\n * hook then either (1) re-syncs from a token another tab refreshed, (2)\n * silently renews when the user has been active, or (3) does nothing when\n * idle — leaving the stale access token in place so unsaved form state\n * survives until the next request refreshes it. A server-confirmed dead\n * session (renewal rejected) broadcasts globally via `onSessionDead`. See\n * `useSessionKeepalive` for the full rationale.\n */\n useSessionKeepalive({\n token,\n onSessionDead: clearStateAndLogout,\n getStoredToken,\n onResync: resyncToken,\n getLastActivityAt,\n renewSession,\n disabled: _disableRenewToken,\n });\n\n React.useEffect(() => {\n /**\n * This will log a user out of all tabs if they log out in one tab.\n */\n const handleUserStorageChange = (event: StorageEvent) => {\n if (event.key === STORAGE_KEYS.STATUS && event.newValue === null) {\n clearStateAndLogout();\n }\n };\n\n window.addEventListener('storage', handleUserStorageChange);\n\n return () => {\n window.removeEventListener('storage', handleUserStorageChange);\n };\n });\n\n const login = React.useCallback<AuthContextValue['login']>(\n async ({ rememberMe, ...body }) => {\n const res = await loginMutation({ ...body, deviceId: getOrCreateDeviceId(), rememberMe });\n\n /**\n * There will always be a `data` key in the response\n * because if something fails, it will throw an error.\n */\n if ('data' in res) {\n const { token } = res.data;\n\n resetSessionExpiredNotification();\n dispatch(\n loginAction({\n token,\n persist: rememberMe,\n })\n );\n }\n\n return res;\n },\n [dispatch, loginMutation]\n );\n\n /**\n * Explicit user logout. Confirm unsaved changes *before* `logoutMutation` so\n * Cancel leaves the server session and client token intact.\n */\n const logout = React.useCallback(async () => {\n runLogoutWithGuard(() => {\n void (async () => {\n try {\n await logoutMutation({ deviceId: getOrCreateDeviceId() });\n } catch {\n // The session may already be invalid.\n }\n performGlobalLogout();\n })();\n });\n }, [logoutMutation, performGlobalLogout, runLogoutWithGuard]);\n\n const refetchPermissions = React.useCallback(async () => {\n if (!isUninitialized) {\n await refetch();\n }\n }, [isUninitialized, refetch]);\n\n const [checkPermissions] = useLazyCheckPermissionsQuery();\n const checkUserHasPermissions: AuthContextValue['checkUserHasPermissions'] = React.useCallback(\n async (\n permissions,\n passedPermissions,\n // TODO:\n // Here we have parameterised checkUserHasPermissions in order to pass\n // query context from elsewhere in the application.\n // See packages/core/content-manager/admin/src/features/DocumentRBAC.tsx\n\n // This is in order to calculate permissions on accurate query params.\n // We should be able to rely on the query params in this provider\n // If we need to pass additional context to the RBAC middleware\n // we should define a better context type.\n rawQueryContext\n ) => {\n /**\n * If there's no permissions to check, then we allow it to\n * pass to preserve existing behaviours.\n *\n * TODO: should we review this? it feels more dangerous than useful.\n */\n if (!permissions || permissions.length === 0) {\n return [{ action: '', subject: '' }];\n }\n\n /**\n * Given the provided permissions, return the permissions from either passedPermissions\n * or userPermissions as this is expected to be the full permission entity.\n */\n const actualUserPermissions = passedPermissions ?? userPermissions;\n\n const matchingPermissions = actualUserPermissions.filter(\n (permission) =>\n permissions.findIndex(\n (perm) =>\n perm.action === permission.action &&\n // Only check the subject if it's provided\n (perm.subject == undefined || perm.subject === permission.subject)\n ) >= 0\n );\n\n const middlewaredPermissions = await runRbacMiddleware(\n {\n user,\n permissions: userPermissions,\n pathname: locationRef.current.pathname,\n search: (rawQueryContext || rawQuery).split('?')[1] ?? '',\n },\n matchingPermissions\n );\n\n const shouldCheckConditions = middlewaredPermissions.some(\n (perm) => Array.isArray(perm.conditions) && perm.conditions.length > 0\n );\n\n if (!shouldCheckConditions) {\n return middlewaredPermissions;\n }\n\n const { data, error } = await checkPermissions({\n permissions: middlewaredPermissions.map((perm) => ({\n action: perm.action,\n subject: perm.subject,\n })),\n });\n\n if (error) {\n throw error;\n } else {\n return middlewaredPermissions.filter((_, index) => data?.data[index] === true);\n }\n },\n [checkPermissions, rawQuery, runRbacMiddleware, user, userPermissions]\n );\n\n const isLoading = isLoadingUser || isLoadingPermissions;\n\n return (\n <>\n <Provider\n token={token}\n user={user}\n login={login}\n logout={logout}\n permissions={userPermissions}\n checkUserHasPermissions={checkUserHasPermissions ?? NOOP_CHECK_USER_HAS_PERMISSIONS}\n refetchPermissions={refetchPermissions}\n isLoading={isLoading}\n >\n {children}\n </Provider>\n <Dialog.Root\n open={isSessionLogoutDialogOpen}\n onOpenChange={handleSessionLogoutDialogOpenChange}\n >\n <ConfirmDialog\n onConfirm={handleConfirmSessionLogout}\n onCancel={handleCancelSessionLogout}\n title={\n LOGOUT_PROMPTS[sessionLogoutReason].title\n ? formatMessage(LOGOUT_PROMPTS[sessionLogoutReason].title)\n : undefined\n }\n // Forced session-dead: no Cancel that pretends the session is still valid.\n startAction={isForcedLogout(sessionLogoutReason) ? <></> : undefined}\n >\n {formatMessage(LOGOUT_PROMPTS[sessionLogoutReason].body)}\n </ConfirmDialog>\n </Dialog.Root>\n </>\n );\n};\n\nexport { AuthProvider, useAuth, STORAGE_KEYS };\nexport type { AuthContextValue, Permission, User };\n"],"names":["NOOP_CHECK_USER_HAS_PERMISSIONS","Provider","useAuth","createContext","STORAGE_KEYS","STATUS","isForcedLogout","reason","LOGOUT_PROMPTS","voluntary","title","undefined","body","id","defaultMessage","AuthProvider","children","_defaultPermissions","_disableRenewToken","formatMessage","useIntl","dispatch","useTypedDispatch","runRbacMiddleware","useStrapiApp","state","rbac","run","location","useLocation","rawQuery","useQueryParams","locationRef","React","useRef","useEffect","current","token","useTypedSelector","admin_app","data","user","isLoading","isLoadingUser","useGetMeQuery","skip","userPermissions","refetch","isUninitialized","isLoadingPermissions","useGetMyPermissionsQuery","navigate","useNavigate","loginMutation","useLoginMutation","logoutMutation","useLogoutMutation","pendingLogoutRef","logoutGuardOpenRef","logoutGuardReasonRef","isSessionLogoutDialogOpen","setIsSessionLogoutDialogOpen","useState","sessionLogoutReason","setSessionLogoutReason","runLogoutWithGuard","useCallback","logoutFn","hasUnsavedChanges","performGlobalLogout","post","getFetchClient","adminApi","util","resetApiState","logoutAction","clearStateAndLogout","handleConfirmSessionLogout","handleCancelSessionLogout","forced","handleSessionLogoutDialogOpenChange","open","resyncToken","newToken","setToken","lastActivityRef","Date","now","markActivity","events","forEach","event","window","addEventListener","passive","capture","removeEventListener","getLastActivityAt","renewSession","attemptTokenRefresh","preferedLanguage","setLocale","normalizeAdminLocale","setOnTokenUpdate","setOnSessionExpired","useSessionKeepalive","onSessionDead","getStoredToken","onResync","disabled","handleUserStorageChange","key","newValue","login","rememberMe","res","deviceId","getOrCreateDeviceId","resetSessionExpiredNotification","loginAction","persist","logout","refetchPermissions","checkPermissions","useLazyCheckPermissionsQuery","checkUserHasPermissions","permissions","passedPermissions","rawQueryContext","length","action","subject","actualUserPermissions","matchingPermissions","filter","permission","findIndex","perm","middlewaredPermissions","pathname","search","split","shouldCheckConditions","some","Array","isArray","conditions","error","map","_","index","_jsxs","_Fragment","_jsx","Dialog","Root","onOpenChange","ConfirmDialog","onConfirm","onCancel","startAction"],"mappings":";;;;;;;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;IAeA,MAAMA,+BAAAA,GAA+E,UAAY,EAAE;AAEnG,MAAM,CAACC,QAAAA,EAAUC,OAAAA,CAAQ,GAAGC,aAAAA,CAAgC,MAAA;AAa5D,MAAMC,YAAAA,GAAe;IAEnBC,MAAAA,EAAQ;AACV;AAaA,MAAMC,cAAAA,GAAiB,CAACC,MAAAA,GAAyBA,MAAAA,KAAW,cAAA;AAE5D;;;;AAIC,IACD,MAAMC,cAAAA,GAAiB;IACrBC,SAAAA,EAAW;QACTC,KAAAA,EAAOC,SAAAA;QACPC,IAAAA,EAAM;YACJC,EAAAA,EAAI,uBAAA;YACJC,cAAAA,EAAgB;AAClB;AACF,KAAA;IACA,cAAA,EAAgB;QACdJ,KAAAA,EAAO;YACLG,EAAAA,EAAI,yBAAA;YACJC,cAAAA,EAAgB;AAClB,SAAA;QACAF,IAAAA,EAAM;YACJC,EAAAA,EAAI,2BAAA;YACJC,cAAAA,EACE;AACJ;AACF;AACF,CAAA;AAEA,MAAMC,YAAAA,GAAe,CA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ACrD,KAAK,CAAA,GACvDC,SAAAA;;oBAGNqJ,WAAAA,EAAa1J,cAAAA,CAAeyD,qCAAuB0F,GAAA,CAAAD,QAAA,EAAA,EAAA,CAAA,GAAQ7I,SAAAA;AAE1DQ,oBAAAA,QAAAA,EAAAA,aAAAA,CAAcX,cAAc,CAACuD,mBAAAA,CAAoB,CAACnD,IAAI;;;;;AAKjE;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var unsavedChangesRegistry = require('../utils/unsavedChangesRegistry.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers whether the current surface has unsaved edits so session-expiry
|
|
8
|
+
* logout can warn before clearing auth state (which unmounts forms).
|
|
9
|
+
*/ const useRegisterUnsavedChanges = (id, enabled)=>{
|
|
10
|
+
React.useEffect(()=>{
|
|
11
|
+
return unsavedChangesRegistry.registerUnsavedChangesCheck(id, ()=>enabled);
|
|
12
|
+
}, [
|
|
13
|
+
id,
|
|
14
|
+
enabled
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.useRegisterUnsavedChanges = useRegisterUnsavedChanges;
|
|
19
|
+
//# sourceMappingURL=useRegisterUnsavedChanges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRegisterUnsavedChanges.js","sources":["../../../../../admin/src/hooks/useRegisterUnsavedChanges.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { registerUnsavedChangesCheck } from '../utils/unsavedChangesRegistry';\n\n/**\n * Registers whether the current surface has unsaved edits so session-expiry\n * logout can warn before clearing auth state (which unmounts forms).\n */\nconst useRegisterUnsavedChanges = (id: string, enabled: boolean): void => {\n useEffect(() => {\n return registerUnsavedChangesCheck(id, () => enabled);\n }, [id, enabled]);\n};\n\nexport { useRegisterUnsavedChanges };\n"],"names":["useRegisterUnsavedChanges","id","enabled","useEffect","registerUnsavedChangesCheck"],"mappings":";;;;;AAIA;;;IAIA,MAAMA,yBAAAA,GAA4B,CAACC,EAAAA,EAAYC,OAAAA,GAAAA;IAC7CC,eAAAA,CAAU,IAAA;QACR,OAAOC,kDAAAA,CAA4BH,IAAI,IAAMC,OAAAA,CAAAA;IAC/C,CAAA,EAAG;AAACD,QAAAA,EAAAA;AAAIC,QAAAA;AAAQ,KAAA,CAAA;AAClB;;;;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { registerUnsavedChangesCheck } from '../utils/unsavedChangesRegistry.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Registers whether the current surface has unsaved edits so session-expiry
|
|
6
|
+
* logout can warn before clearing auth state (which unmounts forms).
|
|
7
|
+
*/ const useRegisterUnsavedChanges = (id, enabled)=>{
|
|
8
|
+
useEffect(()=>{
|
|
9
|
+
return registerUnsavedChangesCheck(id, ()=>enabled);
|
|
10
|
+
}, [
|
|
11
|
+
id,
|
|
12
|
+
enabled
|
|
13
|
+
]);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { useRegisterUnsavedChanges };
|
|
17
|
+
//# sourceMappingURL=useRegisterUnsavedChanges.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRegisterUnsavedChanges.mjs","sources":["../../../../../admin/src/hooks/useRegisterUnsavedChanges.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { registerUnsavedChangesCheck } from '../utils/unsavedChangesRegistry';\n\n/**\n * Registers whether the current surface has unsaved edits so session-expiry\n * logout can warn before clearing auth state (which unmounts forms).\n */\nconst useRegisterUnsavedChanges = (id: string, enabled: boolean): void => {\n useEffect(() => {\n return registerUnsavedChangesCheck(id, () => enabled);\n }, [id, enabled]);\n};\n\nexport { useRegisterUnsavedChanges };\n"],"names":["useRegisterUnsavedChanges","id","enabled","useEffect","registerUnsavedChangesCheck"],"mappings":";;;AAIA;;;IAIA,MAAMA,yBAAAA,GAA4B,CAACC,EAAAA,EAAYC,OAAAA,GAAAA;IAC7CC,SAAAA,CAAU,IAAA;QACR,OAAOC,2BAAAA,CAA4BH,IAAI,IAAMC,OAAAA,CAAAA;IAC/C,CAAA,EAAG;AAACD,QAAAA,EAAAA;AAAIC,QAAAA;AAAQ,KAAA,CAAA;AAClB;;;;"}
|
|
@@ -27,31 +27,38 @@ const SESSION_EXPIRY_BUFFER_MS = 1000;
|
|
|
27
27
|
/**
|
|
28
28
|
* How long before the access token's `exp` an active tab renews. Renewing
|
|
29
29
|
* ahead of expiry (rather than at it) means the refreshed token is already in
|
|
30
|
-
* shared storage by the time any *other* tab's
|
|
31
|
-
* sibling re-syncs instead of racing the refresh
|
|
30
|
+
* shared storage by the time any *other* tab's post-expiry timer fires — so an
|
|
31
|
+
* idle sibling re-syncs instead of racing the refresh.
|
|
32
32
|
*/ const SESSION_RENEW_MARGIN_MS = 10000;
|
|
33
33
|
/**
|
|
34
|
-
* Keep the admin session alive while the user is active
|
|
35
|
-
*
|
|
34
|
+
* Keep the admin session alive while the user is active — without one tab
|
|
35
|
+
* tearing down another, and without logging anyone out because a short-lived
|
|
36
|
+
* access token aged out.
|
|
36
37
|
*
|
|
37
|
-
* The access token
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* The access token (`accessTokenLifespan`, e.g. 30 min) is transport plumbing,
|
|
39
|
+
* not the session length; the refresh token's idle/max window is the session.
|
|
40
|
+
* So expiry of the access JWT must never clear auth state or unmount the page:
|
|
41
|
+
* the next user-initiated request 401s, `withTokenRefresh` refreshes and
|
|
42
|
+
* retries, and only a *rejected* refresh ends the session (`onSessionDead`).
|
|
43
|
+
* Two timers are armed per token:
|
|
40
44
|
*
|
|
41
45
|
* - Renew (at `exp` minus a margin): if the user interacted during this token's
|
|
42
46
|
* lifetime, silently renew *ahead* of expiry. The new `setToken` re-arms the
|
|
43
47
|
* hook; a server rejection (`onSessionDead`) ends the session globally.
|
|
44
48
|
* Renewing early guarantees the refreshed token reaches shared storage before
|
|
45
|
-
* any sibling tab's
|
|
46
|
-
* -
|
|
47
|
-
* first re-syncs from a token another tab refreshed (so an idle tab rides
|
|
48
|
-
* an active sibling), then renews if activity arrived late
|
|
49
|
-
*
|
|
49
|
+
* any sibling tab's post-expiry timer fires.
|
|
50
|
+
* - Post-expiry (just after `exp`): the fallback when this tab did not renew.
|
|
51
|
+
* It first re-syncs from a token another tab refreshed (so an idle tab rides
|
|
52
|
+
* on an active sibling), then renews if activity arrived late. If the tab is
|
|
53
|
+
* still idle, it does nothing destructive — the stale access token stays in
|
|
54
|
+
* place so form state survives until the next request.
|
|
55
|
+
*
|
|
56
|
+
* Idle tabs must not renew: a tab left open forever must not keep the session
|
|
57
|
+
* alive past the server's idle/max window.
|
|
50
58
|
*
|
|
51
59
|
* If the JWT can't be decoded (malformed, missing `exp`), the timers are skipped
|
|
52
|
-
* silently — the
|
|
53
|
-
|
|
54
|
-
*/ const useIdleSessionLogout = ({ token, onExpired, onSessionDead, getStoredToken, onResync, getLastActivityAt, renewSession, disabled = false })=>{
|
|
60
|
+
* silently — the 401 refresh path still covers the next user-initiated request.
|
|
61
|
+
*/ const useSessionKeepalive = ({ token, onSessionDead, getStoredToken, onResync, getLastActivityAt, renewSession, disabled = false })=>{
|
|
55
62
|
React__namespace.useEffect(()=>{
|
|
56
63
|
if (!token || disabled) {
|
|
57
64
|
return undefined;
|
|
@@ -81,7 +88,7 @@ const SESSION_EXPIRY_BUFFER_MS = 1000;
|
|
|
81
88
|
renewSession().then((renewed)=>{
|
|
82
89
|
if (!renewed) {
|
|
83
90
|
// Server rejected the refresh: the session is truly over.
|
|
84
|
-
|
|
91
|
+
onSessionDead?.();
|
|
85
92
|
}
|
|
86
93
|
// On success, storeToken -> setToken updates the token prop, which
|
|
87
94
|
// re-runs this effect and re-arms against the new exp.
|
|
@@ -97,26 +104,26 @@ const SESSION_EXPIRY_BUFFER_MS = 1000;
|
|
|
97
104
|
renew();
|
|
98
105
|
}
|
|
99
106
|
}, renewDelay);
|
|
100
|
-
// Fallback
|
|
101
|
-
|
|
102
|
-
const
|
|
107
|
+
// Fallback just after expiry for tabs that did not renew: re-sync or
|
|
108
|
+
// late-activity renew. Idle tabs leave the stale token alone.
|
|
109
|
+
const postExpiryDelay = Math.max(expiry - armedAt + SESSION_EXPIRY_BUFFER_MS, 0);
|
|
110
|
+
const postExpiryTimeoutId = window.setTimeout(()=>{
|
|
103
111
|
if (tryResync()) {
|
|
104
112
|
return;
|
|
105
113
|
}
|
|
106
114
|
if (wasActive() && renewSession) {
|
|
107
115
|
renew();
|
|
108
|
-
return;
|
|
109
116
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
117
|
+
// Genuinely idle: do nothing. Keep the (stale) access token and the page
|
|
118
|
+
// mounted. The next request will 401 and either refresh transparently or
|
|
119
|
+
// hit the session-dead path if the server rejects the refresh.
|
|
120
|
+
}, postExpiryDelay);
|
|
113
121
|
return ()=>{
|
|
114
122
|
window.clearTimeout(renewTimeoutId);
|
|
115
|
-
window.clearTimeout(
|
|
123
|
+
window.clearTimeout(postExpiryTimeoutId);
|
|
116
124
|
};
|
|
117
125
|
}, [
|
|
118
126
|
token,
|
|
119
|
-
onExpired,
|
|
120
127
|
onSessionDead,
|
|
121
128
|
getStoredToken,
|
|
122
129
|
onResync,
|
|
@@ -128,5 +135,5 @@ const SESSION_EXPIRY_BUFFER_MS = 1000;
|
|
|
128
135
|
|
|
129
136
|
exports.SESSION_EXPIRY_BUFFER_MS = SESSION_EXPIRY_BUFFER_MS;
|
|
130
137
|
exports.SESSION_RENEW_MARGIN_MS = SESSION_RENEW_MARGIN_MS;
|
|
131
|
-
exports.
|
|
132
|
-
//# sourceMappingURL=
|
|
138
|
+
exports.useSessionKeepalive = useSessionKeepalive;
|
|
139
|
+
//# sourceMappingURL=useSessionKeepalive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSessionKeepalive.js","sources":["../../../../../admin/src/hooks/useSessionKeepalive.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { decodeAccessTokenExpiry } from '../utils/jwt';\n\nconst SESSION_EXPIRY_BUFFER_MS = 1000;\n/**\n * How long before the access token's `exp` an active tab renews. Renewing\n * ahead of expiry (rather than at it) means the refreshed token is already in\n * shared storage by the time any *other* tab's post-expiry timer fires — so an\n * idle sibling re-syncs instead of racing the refresh.\n */\nconst SESSION_RENEW_MARGIN_MS = 10_000;\n\ninterface UseSessionKeepaliveOptions {\n /**\n * The current admin access JWT (from Redux), or `null` when logged out.\n */\n token: string | null;\n /**\n * Called when a renewal attempt is rejected by the server (the session is\n * truly over: refresh token idle/max window elapsed). This is a\n * server-confirmed end of session, so it SHOULD broadcast a global logout to\n * every tab.\n */\n onSessionDead?: () => void;\n /**\n * Read the access token currently in shared storage (localStorage/cookie).\n * Because every open tab shares the same refresh cookie, an active tab that\n * refreshes writes a newer access token here. When omitted, the hook never\n * re-syncs across tabs.\n */\n getStoredToken?: () => string | null;\n /**\n * Adopt a newer shared token instead of treating this tab's token as stale.\n * Typically dispatches `setToken`, which updates Redux and causes this hook\n * to re-arm against the later `exp`. Only called when `getStoredToken`\n * returns a token whose `exp` is later than the in-memory one.\n */\n onResync?: (token: string) => void;\n /**\n * Epoch ms of the user's last interaction (pointer, key, scroll, …). Used to\n * decide whether to silently renew when the access token is about to expire.\n * Idle tabs must NOT renew — that would defeat the server's\n * `idleSessionLifespan` / `idleRefreshTokenLifespan`. When omitted, the hook\n * never treats the tab as active.\n */\n getLastActivityAt?: () => number;\n /**\n * Silently renew the session (rotate the refresh token + mint a new access\n * token). Resolves `true` on success — the resulting `setToken` re-arms this\n * hook against the new `exp` — or `false` when the server rejects it. Only\n * called when the user was active during the current token's lifetime.\n */\n renewSession?: () => Promise<boolean>;\n /**\n * Escape hatch for tests / dev environments where we don't want the\n * automatic renew / re-sync behavior. Mirrors the existing `_disableRenewToken`\n * prop on `<AuthProvider>`.\n */\n disabled?: boolean;\n}\n\n/**\n * Keep the admin session alive while the user is active — without one tab\n * tearing down another, and without logging anyone out because a short-lived\n * access token aged out.\n *\n * The access token (`accessTokenLifespan`, e.g. 30 min) is transport plumbing,\n * not the session length; the refresh token's idle/max window is the session.\n * So expiry of the access JWT must never clear auth state or unmount the page:\n * the next user-initiated request 401s, `withTokenRefresh` refreshes and\n * retries, and only a *rejected* refresh ends the session (`onSessionDead`).\n * Two timers are armed per token:\n *\n * - Renew (at `exp` minus a margin): if the user interacted during this token's\n * lifetime, silently renew *ahead* of expiry. The new `setToken` re-arms the\n * hook; a server rejection (`onSessionDead`) ends the session globally.\n * Renewing early guarantees the refreshed token reaches shared storage before\n * any sibling tab's post-expiry timer fires.\n * - Post-expiry (just after `exp`): the fallback when this tab did not renew.\n * It first re-syncs from a token another tab refreshed (so an idle tab rides\n * on an active sibling), then renews if activity arrived late. If the tab is\n * still idle, it does nothing destructive — the stale access token stays in\n * place so form state survives until the next request.\n *\n * Idle tabs must not renew: a tab left open forever must not keep the session\n * alive past the server's idle/max window.\n *\n * If the JWT can't be decoded (malformed, missing `exp`), the timers are skipped\n * silently — the 401 refresh path still covers the next user-initiated request.\n */\nconst useSessionKeepalive = ({\n token,\n onSessionDead,\n getStoredToken,\n onResync,\n getLastActivityAt,\n renewSession,\n disabled = false,\n}: UseSessionKeepaliveOptions): void => {\n React.useEffect(() => {\n if (!token || disabled) {\n return undefined;\n }\n\n const expiry = decodeAccessTokenExpiry(token);\n if (expiry === null) {\n return undefined;\n }\n\n // When this token became active. Activity recorded after this point means\n // the user was present during the token's lifetime.\n const armedAt = Date.now();\n const wasActive = () =>\n typeof getLastActivityAt === 'function' && getLastActivityAt() >= armedAt;\n\n // Adopt a fresher token another tab wrote to shared storage. Returns true\n // when it re-synced (caller should stop).\n const tryResync = (): boolean => {\n const storedToken = getStoredToken?.() ?? null;\n if (storedToken && storedToken !== token && onResync) {\n const storedExpiry = decodeAccessTokenExpiry(storedToken);\n if (storedExpiry !== null && storedExpiry > expiry) {\n onResync(storedToken);\n return true;\n }\n }\n return false;\n };\n\n const renew = () => {\n renewSession!().then((renewed) => {\n if (!renewed) {\n // Server rejected the refresh: the session is truly over.\n onSessionDead?.();\n }\n // On success, storeToken -> setToken updates the token prop, which\n // re-runs this effect and re-arms against the new exp.\n });\n };\n\n // Renew ahead of expiry while the user is active.\n const renewDelay = Math.max(expiry - armedAt - SESSION_RENEW_MARGIN_MS, 0);\n const renewTimeoutId = window.setTimeout(() => {\n if (tryResync()) {\n return;\n }\n if (wasActive() && renewSession) {\n renew();\n }\n }, renewDelay);\n\n // Fallback just after expiry for tabs that did not renew: re-sync or\n // late-activity renew. Idle tabs leave the stale token alone.\n const postExpiryDelay = Math.max(expiry - armedAt + SESSION_EXPIRY_BUFFER_MS, 0);\n const postExpiryTimeoutId = window.setTimeout(() => {\n if (tryResync()) {\n return;\n }\n if (wasActive() && renewSession) {\n renew();\n }\n // Genuinely idle: do nothing. Keep the (stale) access token and the page\n // mounted. The next request will 401 and either refresh transparently or\n // hit the session-dead path if the server rejects the refresh.\n }, postExpiryDelay);\n\n return () => {\n window.clearTimeout(renewTimeoutId);\n window.clearTimeout(postExpiryTimeoutId);\n };\n }, [token, onSessionDead, getStoredToken, onResync, getLastActivityAt, renewSession, disabled]);\n};\n\nexport { useSessionKeepalive, SESSION_EXPIRY_BUFFER_MS, SESSION_RENEW_MARGIN_MS };\nexport type { UseSessionKeepaliveOptions };\n"],"names":["SESSION_EXPIRY_BUFFER_MS","SESSION_RENEW_MARGIN_MS","useSessionKeepalive","token","onSessionDead","getStoredToken","onResync","getLastActivityAt","renewSession","disabled","React","useEffect","undefined","expiry","decodeAccessTokenExpiry","armedAt","Date","now","wasActive","tryResync","storedToken","storedExpiry","renew","then","renewed","renewDelay","Math","max","renewTimeoutId","window","setTimeout","postExpiryDelay","postExpiryTimeoutId","clearTimeout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAMA,wBAAAA,GAA2B;AACjC;;;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