diff --git a/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx b/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx index ba3c5ff0d3212..c2a706adaf1b0 100644 --- a/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx +++ b/packages/frontend/core/src/desktop/pages/auth/oauth-callback.tsx @@ -1,3 +1,4 @@ +import { extractLinkSearchParams } from '@affine/core/utils/link'; import { useService } from '@toeverything/infra'; import { useEffect, useRef } from 'react'; import { @@ -27,9 +28,7 @@ type LoaderData = z.infer; type ParsedState = z.infer; async function parseState(url: string): Promise { - const { code, state: stateStr } = Array.from( - new URL(url).searchParams.entries() - ).reduce((acc, [k, v]) => ((acc[k] = v), acc), {} as Record); + const { code, state: stateStr } = extractLinkSearchParams(url); if (!code || !stateStr) throw new Error('Invalid oauth callback parameters'); try { /** @deprecated old client compatibility*/ diff --git a/packages/frontend/core/src/desktop/pages/open-app/index.tsx b/packages/frontend/core/src/desktop/pages/open-app/index.tsx index c3d0c53ca1f12..2037f587c603d 100644 --- a/packages/frontend/core/src/desktop/pages/open-app/index.tsx +++ b/packages/frontend/core/src/desktop/pages/open-app/index.tsx @@ -1,6 +1,7 @@ import { GraphQLService } from '@affine/core/modules/cloud'; import { OpenInAppPage } from '@affine/core/modules/open-in-app/views/open-in-app-page'; import { appSchemaUrl, appSchemes, channelToScheme } from '@affine/core/utils'; +import { extractLinkSearchParams } from '@affine/core/utils/link'; import type { GetCurrentUserQuery } from '@affine/graphql'; import { getCurrentUserQuery } from '@affine/graphql'; import { useService } from '@toeverything/infra'; @@ -27,13 +28,7 @@ export const loader: LoaderFunction = async args => { const action = args.params.action || ''; try { - const { url, ...params } = Array.from( - new URL(args.request.url).searchParams.entries() - ).reduce( - (acc, [k, v]) => ((acc[k] = v), acc), - {} as Record - ); - + const { url, ...params } = extractLinkSearchParams(args.request.url); return LoaderData.parse({ action, url, params }); } catch (e) { console.error(e); diff --git a/packages/frontend/core/src/utils/link.ts b/packages/frontend/core/src/utils/link.ts new file mode 100644 index 0000000000000..1ac15781885dd --- /dev/null +++ b/packages/frontend/core/src/utils/link.ts @@ -0,0 +1,6 @@ +export function extractLinkSearchParams(link: string): Record { + return Array.from(new URL(link).searchParams.entries()).reduce( + (acc, [k, v]) => ((acc[k] = v), acc), + {} as Record + ); +}