@opexa/portal-components 0.0.332 → 0.0.333
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/components/PortalProvider/PortalProvider.js +2 -1
- package/dist/components/PortalProvider/SessionWatcher.d.ts +1 -0
- package/dist/components/PortalProvider/SessionWatcher.js +22 -0
- package/dist/handlers/getSession.js +8 -0
- package/dist/handlers/postAuthenticate.js +3 -0
- package/dist/handlers/postSession.js +3 -0
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import { getQueryClient } from '../../utils/getQueryClient.js';
|
|
|
9
9
|
import { FeatureFlag } from './FeatureFlag.js';
|
|
10
10
|
import { LinkGoogleAccountObserver } from './LinkGoogleAccountObserver.js';
|
|
11
11
|
import { Providers } from './Providers.js';
|
|
12
|
+
import { SessionWatcher } from './SessionWatcher.js';
|
|
12
13
|
import { SetupCellxpertCxd } from './SetupCellxpertCxd.js';
|
|
13
14
|
import { SetupDomain } from './SetupDomain.js';
|
|
14
15
|
import { Snackbar } from './Snackbar.js';
|
|
@@ -20,5 +21,5 @@ export async function PortalProvider({ recaptchaSiteKey, children, }) {
|
|
|
20
21
|
prefetchAccountQuery(),
|
|
21
22
|
prefetchWalletQuery(),
|
|
22
23
|
]);
|
|
23
|
-
return (_jsxs(Fragment, { children: [_jsx(Providers, { recaptchaSiteKey: recaptchaSiteKey, children: _jsxs(HydrationBoundary, { state: dehydrate(queryClient), children: [children, _jsx(Suspense, { children: _jsx(SetupDomain, {}) }), _jsx(Suspense, { children: _jsx(SetupCellxpertCxd, {}) })] }) }), _jsx(Snackbar, {}), _jsx(Suspense, { children: _jsx(LinkGoogleAccountObserver, {}) }), _jsx(Suspense, { children: _jsx(FeatureFlag, {}) })] }));
|
|
24
|
+
return (_jsxs(Fragment, { children: [_jsx(Providers, { recaptchaSiteKey: recaptchaSiteKey, children: _jsxs(HydrationBoundary, { state: dehydrate(queryClient), children: [children, _jsx(SessionWatcher, {}), _jsx(Suspense, { children: _jsx(SetupDomain, {}) }), _jsx(Suspense, { children: _jsx(SetupCellxpertCxd, {}) })] }) }), _jsx(Snackbar, {}), _jsx(Suspense, { children: _jsx(LinkGoogleAccountObserver, {}) }), _jsx(Suspense, { children: _jsx(FeatureFlag, {}) })] }));
|
|
24
25
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function SessionWatcher(): null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useRouter } from 'next/navigation';
|
|
3
|
+
import { useTimeout } from 'usehooks-ts';
|
|
4
|
+
import { useSessionHealthQuery } from '../../client/hooks/useSessionHealthQuery.js';
|
|
5
|
+
import { useSessionQuery } from '../../client/hooks/useSessionQuery.js';
|
|
6
|
+
import { useSignOutMutation } from '../../client/hooks/useSignOutMutation.js';
|
|
7
|
+
export function SessionWatcher() {
|
|
8
|
+
const router = useRouter();
|
|
9
|
+
const sessionQuery = useSessionQuery();
|
|
10
|
+
const sessionHealthQuery = useSessionHealthQuery({
|
|
11
|
+
enabled: sessionQuery.data?.status === 'authenticated',
|
|
12
|
+
refetchInterval: 1000 * 5,
|
|
13
|
+
});
|
|
14
|
+
const signOutMutation = useSignOutMutation({
|
|
15
|
+
onSuccess() {
|
|
16
|
+
router.refresh();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const healthy = sessionHealthQuery.data ?? true;
|
|
20
|
+
useTimeout(() => signOutMutation.mutate(), !healthy ? 250 : null);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
@@ -22,9 +22,17 @@ export async function getSession(request) {
|
|
|
22
22
|
}
|
|
23
23
|
if (!accessToken) {
|
|
24
24
|
try {
|
|
25
|
+
const forwarded = request.headers.get('x-forwarded-for');
|
|
26
|
+
const ipaddress = forwarded?.split(',')[0];
|
|
25
27
|
const data = await refreshSession({
|
|
26
28
|
headers: {
|
|
27
29
|
Authorization: `Bearer ${refreshToken}`,
|
|
30
|
+
...(ipaddress && {
|
|
31
|
+
'X-Forwarded-For': ipaddress,
|
|
32
|
+
}),
|
|
33
|
+
...(ipaddress && {
|
|
34
|
+
'X-User-Real-Ip': ipaddress,
|
|
35
|
+
}),
|
|
28
36
|
},
|
|
29
37
|
});
|
|
30
38
|
const response = NextResponse.json({
|