@opexa/portal-components 0.0.563 → 0.0.564
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.
|
@@ -18,7 +18,11 @@ export const useSessionHealthQuery = (config) => {
|
|
|
18
18
|
queryFn: async ({ signal }) => {
|
|
19
19
|
const session = await getQueryClient().fetchQuery({
|
|
20
20
|
queryKey: getSessionQueryKey(),
|
|
21
|
-
queryFn: async () =>
|
|
21
|
+
queryFn: async () => {
|
|
22
|
+
const result = await getSession();
|
|
23
|
+
return result;
|
|
24
|
+
},
|
|
25
|
+
staleTime: 0,
|
|
22
26
|
});
|
|
23
27
|
invariant(session.status === 'authenticated');
|
|
24
28
|
const ok = await getSessionHealth({
|
|
@@ -3,11 +3,24 @@ import { NextResponse } from 'next/server';
|
|
|
3
3
|
import { ACCESS_TOKEN_COOKIE_NAME, BTAG_COOKIE_NAME, DOMAIN_COOKIE_NAME, REFRESH_TOKEN_COOKIE_NAME, } from '../constants/index.js';
|
|
4
4
|
import { refreshSession } from '../services/auth.js';
|
|
5
5
|
export async function getSession(request) {
|
|
6
|
-
|
|
6
|
+
let accessToken = request.cookies.get(ACCESS_TOKEN_COOKIE_NAME)?.value;
|
|
7
|
+
let isAccessTokenValid = true;
|
|
8
|
+
if (accessToken) {
|
|
9
|
+
try {
|
|
10
|
+
const payload = accessToken.split('.')[1];
|
|
11
|
+
const decoded = JSON.parse(Buffer.from(payload, 'base64').toString('utf8'));
|
|
12
|
+
if (decoded.exp && Date.now() / 1000 > decoded.exp) {
|
|
13
|
+
isAccessTokenValid = false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
isAccessTokenValid = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
7
20
|
const refreshToken = request.cookies.get(REFRESH_TOKEN_COOKIE_NAME)?.value;
|
|
8
21
|
const domain = request.cookies.get(DOMAIN_COOKIE_NAME)?.value;
|
|
9
22
|
const btag = request.cookies.get(BTAG_COOKIE_NAME)?.value;
|
|
10
|
-
if (!refreshToken) {
|
|
23
|
+
if (!refreshToken || !isAccessTokenValid) {
|
|
11
24
|
const response = NextResponse.json({
|
|
12
25
|
ok: true,
|
|
13
26
|
data: {
|
|
@@ -20,7 +33,7 @@ export async function getSession(request) {
|
|
|
20
33
|
response.cookies.delete(REFRESH_TOKEN_COOKIE_NAME);
|
|
21
34
|
return response;
|
|
22
35
|
}
|
|
23
|
-
if (!accessToken) {
|
|
36
|
+
if (!accessToken || !isAccessTokenValid) {
|
|
24
37
|
try {
|
|
25
38
|
const ipAddress = request.headers
|
|
26
39
|
.get('x-forwarded-for')
|