diff --git a/src/app/pages/auth/login/oidcLoginUtil.test.ts b/src/app/pages/auth/login/oidcLoginUtil.test.ts index 0170c213e..4ca4a2aa1 100644 --- a/src/app/pages/auth/login/oidcLoginUtil.test.ts +++ b/src/app/pages/auth/login/oidcLoginUtil.test.ts @@ -42,11 +42,11 @@ describe('expiresInMsFromToken', () => { }); const mocks = vi.hoisted(() => ({ - oauth2Context: vi.fn(), + oauth2Context: vi.fn<(context: unknown) => void>(), completeAuthorizationCodeGrant: vi.fn<(code: string) => Promise>(), getAuthMetadata: vi.fn<() => Promise>(), - whoami: vi.fn(), - setAccessToken: vi.fn(), + whoami: vi.fn<() => Promise<{ user_id: string; device_id?: string }>>(), + setAccessToken: vi.fn<(token: string) => void>(), })); vi.mock('$types/matrix-sdk', async (importOriginal) => { @@ -60,11 +60,13 @@ vi.mock('$types/matrix-sdk', async (importOriginal) => { public completeAuthorizationCodeGrant = mocks.completeAuthorizationCodeGrant; public context = { deviceId: 'dev', codeVerifier: 'verifier' }; }, - createClient: vi.fn().mockImplementation(() => ({ - getAuthMetadata: mocks.getAuthMetadata, - setAccessToken: mocks.setAccessToken, - whoami: mocks.whoami, - })), + createClient: vi + .fn<(opts: { baseUrl: string; fetchFn: typeof fetch }) => Record>() + .mockImplementation(() => ({ + getAuthMetadata: mocks.getAuthMetadata, + setAccessToken: mocks.setAccessToken, + whoami: mocks.whoami, + })), }; }); diff --git a/src/app/pages/client/BackgroundNotifications.tsx b/src/app/pages/client/BackgroundNotifications.tsx index be8cdc92c..293d4e78d 100644 --- a/src/app/pages/client/BackgroundNotifications.tsx +++ b/src/app/pages/client/BackgroundNotifications.tsx @@ -86,10 +86,6 @@ const startBackgroundClient = async (session: Session): Promise => const tempClient = createClient({ baseUrl: session.baseUrl, fetchFn: fetch, - accessToken: session.accessToken, - refreshToken: session.refreshToken, - userId: session.userId, - deviceId: session.deviceId, }); const tokenRefresher = createSessionTokenRefresher(session, tempClient); diff --git a/src/app/pages/pathUtils.test.ts b/src/app/pages/pathUtils.test.ts index 3928d7750..d72b19277 100644 --- a/src/app/pages/pathUtils.test.ts +++ b/src/app/pages/pathUtils.test.ts @@ -32,11 +32,11 @@ describe('getAppPathFromHref', () => { ).toBe('/login?code=c&state=s'); }); - it('returns empty when the href origin does not match the base', () => { - expect(getAppPathFromHref('https://app.sable.moe/', 'https://tauri.localhost/')).toBe(''); + it('extracts the path from the href when the origin does not match the base (Tauri)', () => { + expect(getAppPathFromHref('https://app.sable.moe/', 'https://tauri.localhost/')).toBe('/'); expect( getAppPathFromHref('https://app.sable.moe/', 'https://tauri.localhost/login?code=c&state=s') - ).toBe(''); + ).toBe('/login?code=c&state=s'); }); it('returns empty when a hash-router base is paired with a hashless href', () => { diff --git a/src/app/pages/pathUtils.ts b/src/app/pages/pathUtils.ts index 37cfc0606..18981c572 100644 --- a/src/app/pages/pathUtils.ts +++ b/src/app/pages/pathUtils.ts @@ -71,18 +71,16 @@ export const getAppPathFromHref = (baseUrl: string, href: string): string => { const trimmedBaseUrl = trimLeadingSlash(baseUrl.slice(baseHashIndex + 1)); const trimmedHref = trimLeadingSlash(href.slice(hrefHashIndex + 1)); - // On Tauri the base origin is synthetic and never matches the href origin; guard - // against slicing a basename the href does not start with. const appPath = trimmedHref.startsWith(trimmedBaseUrl) ? trimmedHref.slice(trimmedBaseUrl.length) : ''; return `/${trimLeadingSlash(appPath)}`; } - // On Tauri the base origin is synthetic and never matches the href origin; return - // empty instead of slicing a garbage path that would be stored as a redirect. const trimmedBaseUrl = trimTrailingSlash(baseUrl); - return href.startsWith(trimmedBaseUrl) ? href.slice(trimmedBaseUrl.length) : ''; + if (href.startsWith(trimmedBaseUrl)) return href.slice(trimmedBaseUrl.length); + const { pathname, search } = new URL(href); + return pathname + search; }; export const getRootPath = (): string => ROOT_PATH; diff --git a/src/client/initMatrix.ts b/src/client/initMatrix.ts index f1edf6f3f..b463b3139 100644 --- a/src/client/initMatrix.ts +++ b/src/client/initMatrix.ts @@ -260,10 +260,6 @@ const buildClient = async (session: Session): Promise => { const tempClient = createClient({ baseUrl: session.baseUrl, fetchFn: fetch, - accessToken: session.accessToken, - refreshToken: session.refreshToken, - userId: session.userId, - deviceId: session.deviceId, }); const tokenRefresher = createSessionTokenRefresher(session, tempClient);