0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core, experience): remove no_cache param

This commit is contained in:
Gao Sun 2024-07-08 09:03:45 +08:00
parent 3a839f6d60
commit a6f96f1d8d
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
5 changed files with 15 additions and 23 deletions

View file

@ -134,14 +134,14 @@ describe('buildLoginPromptUrl', () => {
it('should return the correct url for empty parameters', () => { it('should return the correct url for empty parameters', () => {
expect(buildLoginPromptUrl({})).toBe('sign-in'); expect(buildLoginPromptUrl({})).toBe('sign-in');
expect(buildLoginPromptUrl({}, 'foo')).toBe('sign-in'); expect(buildLoginPromptUrl({}, 'foo')).toBe('sign-in');
expect(buildLoginPromptUrl({}, demoAppApplicationId)).toBe('sign-in?no_cache='); expect(buildLoginPromptUrl({}, demoAppApplicationId)).toBe('sign-in');
}); });
it('should return the correct url for firstScreen', () => { it('should return the correct url for firstScreen', () => {
expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register })).toBe('register'); expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register })).toBe('register');
expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register }, 'foo')).toBe('register'); expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register }, 'foo')).toBe('register');
expect(buildLoginPromptUrl({ first_screen: FirstScreen.SignIn }, demoAppApplicationId)).toBe( expect(buildLoginPromptUrl({ first_screen: FirstScreen.SignIn }, demoAppApplicationId)).toBe(
'sign-in?no_cache=' 'sign-in'
); );
// Legacy interactionMode support // Legacy interactionMode support
expect(buildLoginPromptUrl({ interaction_mode: InteractionMode.SignUp })).toBe('register'); expect(buildLoginPromptUrl({ interaction_mode: InteractionMode.SignUp })).toBe('register');
@ -155,7 +155,7 @@ describe('buildLoginPromptUrl', () => {
'direct/method/target?fallback=sign-in' 'direct/method/target?fallback=sign-in'
); );
expect(buildLoginPromptUrl({ direct_sign_in: 'method:target' }, demoAppApplicationId)).toBe( expect(buildLoginPromptUrl({ direct_sign_in: 'method:target' }, demoAppApplicationId)).toBe(
'direct/method/target?no_cache=&fallback=sign-in' 'direct/method/target?fallback=sign-in'
); );
expect(buildLoginPromptUrl({ direct_sign_in: 'method' })).toBe( expect(buildLoginPromptUrl({ direct_sign_in: 'method' })).toBe(
'direct/method?fallback=sign-in' 'direct/method?fallback=sign-in'
@ -172,6 +172,6 @@ describe('buildLoginPromptUrl', () => {
{ first_screen: FirstScreen.Register, direct_sign_in: 'method:target' }, { first_screen: FirstScreen.Register, direct_sign_in: 'method:target' },
demoAppApplicationId demoAppApplicationId
) )
).toBe('direct/method/target?no_cache=&fallback=register'); ).toBe('direct/method/target?fallback=register');
}); });
}); });

View file

@ -6,7 +6,6 @@ import {
customClientMetadataGuard, customClientMetadataGuard,
GrantType, GrantType,
ExtraParamsKey, ExtraParamsKey,
demoAppApplicationId,
FirstScreen, FirstScreen,
experience, experience,
} from '@logto/schemas'; } from '@logto/schemas';
@ -91,10 +90,6 @@ export const buildLoginPromptUrl = (params: ExtraParamsObject, appId?: unknown):
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
const getSearchParamString = () => (searchParams.size > 0 ? `?${searchParams.toString()}` : ''); const getSearchParamString = () => (searchParams.size > 0 ? `?${searchParams.toString()}` : '');
if (appId === demoAppApplicationId) {
searchParams.append('no_cache', '');
}
if (directSignIn) { if (directSignIn) {
searchParams.append('fallback', firstScreen); searchParams.append('fallback', firstScreen);
const [method, target] = directSignIn.split(':'); const [method, target] = directSignIn.split(':');

View file

@ -22,7 +22,6 @@ export const getSignInExperience = async <T extends SignInExperienceResponse>():
return ky return ky
.get('/api/.well-known/sign-in-exp', { .get('/api/.well-known/sign-in-exp', {
searchParams: buildSearchParameters({ searchParams: buildSearchParameters({
[searchKeys.noCache]: sessionStorage.getItem(searchKeys.noCache),
[searchKeys.organizationId]: sessionStorage.getItem(searchKeys.organizationId), [searchKeys.organizationId]: sessionStorage.getItem(searchKeys.organizationId),
}), }),
}) })
@ -50,7 +49,6 @@ export const getPhrases = async ({
}) })
.get('/api/.well-known/phrases', { .get('/api/.well-known/phrases', {
searchParams: buildSearchParameters({ searchParams: buildSearchParameters({
[searchKeys.noCache]: sessionStorage.getItem(searchKeys.noCache),
lng: language, lng: language,
}), }),
}); });

View file

@ -8,7 +8,6 @@
<!--Preload well-known settings API--> <!--Preload well-known settings API-->
<script> <script>
const { search } = window.location; const { search } = window.location;
const noCache = search.includes('no_cache');
const isPreview = search.includes('preview'); const isPreview = search.includes('preview');
// Preview mode does not query sign-in-exp and phrases // Preview mode does not query sign-in-exp and phrases
const preLoadLinks = isPreview ? [] : ['/api/.well-known/sign-in-exp', '/api/.well-known/phrases']; const preLoadLinks = isPreview ? [] : ['/api/.well-known/sign-in-exp', '/api/.well-known/phrases'];
@ -17,7 +16,7 @@
preLoadLinks.forEach((linkUrl) => { preLoadLinks.forEach((linkUrl) => {
const link = document.createElement('link'); const link = document.createElement('link');
link.rel = 'preload'; link.rel = 'preload';
link.href = `${linkUrl}${noCache ? '?no_cache=true' : ''}`; link.href = linkUrl
link.as = 'fetch'; link.as = 'fetch';
link.crossOrigin = 'anonymous'; link.crossOrigin = 'anonymous';
document.head.appendChild(link); document.head.appendChild(link);

View file

@ -1,7 +1,6 @@
import { condString } from '@silverhand/essentials'; import { condString } from '@silverhand/essentials';
export const searchKeys = Object.freeze({ export const searchKeys = Object.freeze({
noCache: 'no_cache',
/** /**
* The key for specifying the organization ID that may be used to override the default settings. * The key for specifying the organization ID that may be used to override the default settings.
*/ */
@ -15,17 +14,18 @@ export const handleSearchParametersData = () => {
return; return;
} }
// TODO: will refactor soon
const parameters = new URLSearchParams(search); const parameters = new URLSearchParams(search);
if (parameters.get(searchKeys.noCache) !== null) { // Store known search keys to the session storage and remove them from the URL to keep the URL
sessionStorage.setItem(searchKeys.noCache, 'true'); // clean.
} for (const key of Object.values(searchKeys)) {
const value = parameters.get(key);
const organizationId = parameters.get(searchKeys.organizationId); if (value) {
if (organizationId) { sessionStorage.setItem(key, value);
sessionStorage.setItem(searchKeys.organizationId, organizationId); parameters.delete(key);
parameters.delete(searchKeys.organizationId); } else {
sessionStorage.removeItem(key);
}
} }
window.history.replaceState( window.history.replaceState(