From 6190cd80f4eb7683a7633e05e1a4c39e526315a2 Mon Sep 17 00:00:00 2001 From: panagiotis vourtsis Date: Fri, 17 Nov 2023 17:34:43 +0200 Subject: [PATCH] feat: add fresh=true to request fresh membership --- package.json | 5 +++-- src/authentication/Authentication.tsx | 8 ++++++-- yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3544e22b..25e7b52b 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,11 @@ "@auth0/auth0-spa-js": "^2.1.2", "axios": "^0.21.4", "axios-mock-adapter": "^1.19.0", + "dayjs": "^1.11.10", "jwt-decode": "^3.1.2", "react-error-boundary": "^3.1.4", - "zustand": "^4.0.0-rc.1", - "react-router-dom": "^5.3.1" + "react-router-dom": "^5.3.1", + "zustand": "^4.0.0-rc.1" }, "devDependencies": { "@amanda-mitchell/semantic-release-npm-multiple": "^3.5.0", diff --git a/src/authentication/Authentication.tsx b/src/authentication/Authentication.tsx index 5156ea48..fc6e839c 100644 --- a/src/authentication/Authentication.tsx +++ b/src/authentication/Authentication.tsx @@ -3,6 +3,7 @@ import * as Sentry from '@sentry/browser'; import React, { useEffect, useState } from 'react'; import { ErrorBoundary } from 'react-error-boundary'; +import dayjs from 'dayjs'; import { orfiumIdBaseInstance } from '../request'; import useOrganization, { Organization } from '../store/useOrganization'; import { Box, LoadingContent, Wrapper } from './Authentication.style'; @@ -43,7 +44,7 @@ Authentication.TopBar = TopBar; * This is the main component that is wrapped on the authentication. */ const AuthenticationWrapper: React.FunctionComponent = ({ children }) => { - const { isLoading, isAuthenticated, getAccessTokenSilently, logout, loginWithRedirect } = + const { isLoading, isAuthenticated, getAccessTokenSilently, logout, loginWithRedirect, user } = useAuthentication(); const { organizations, setOrganizations, setSelectedOrganization, selectedOrganization } = useOrganization(); @@ -66,7 +67,10 @@ const AuthenticationWrapper: React.FunctionComponent = ({ children }) => { const requestInstance = orfiumIdBaseInstance.createRequest({ method: 'get', url: '/memberships/', - params: config.productCode ? { product_code: config.productCode } : undefined, + params: { + ...(config.productCode ? { product_code: config.productCode } : {}), + fresh: dayjs(user?.updated_at).isAfter(dayjs().subtract(1, 'minute')) || undefined, + }, }); const data = await requestInstance.request(); diff --git a/yarn.lock b/yarn.lock index 1dca4849..d893e4c5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3786,6 +3786,11 @@ data-urls@^2.0.0: whatwg-mimetype "^2.3.0" whatwg-url "^8.0.0" +dayjs@^1.11.10: + version "1.11.10" + resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.10.tgz#68acea85317a6e164457d6d6947564029a6a16a0" + integrity sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ== + dayjs@^1.8.34: version "1.11.6" resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.11.6.tgz#2e79a226314ec3ec904e3ee1dd5a4f5e5b1c7afb"