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', () => {
expect(buildLoginPromptUrl({})).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', () => {
expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register })).toBe('register');
expect(buildLoginPromptUrl({ first_screen: FirstScreen.Register }, 'foo')).toBe('register');
expect(buildLoginPromptUrl({ first_screen: FirstScreen.SignIn }, demoAppApplicationId)).toBe(
'sign-in?no_cache='
'sign-in'
);
// Legacy interactionMode support
expect(buildLoginPromptUrl({ interaction_mode: InteractionMode.SignUp })).toBe('register');
@ -155,7 +155,7 @@ describe('buildLoginPromptUrl', () => {
'direct/method/target?fallback=sign-in'
);
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(
'direct/method?fallback=sign-in'
@ -172,6 +172,6 @@ describe('buildLoginPromptUrl', () => {
{ first_screen: FirstScreen.Register, direct_sign_in: 'method:target' },
demoAppApplicationId
)
).toBe('direct/method/target?no_cache=&fallback=register');
).toBe('direct/method/target?fallback=register');
});
});

View file

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

View file

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

View file

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

View file

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