fix(native): the app's browser sign-in no longer lands on the dashboard when the browser still holds an older TREK

A browser that ran TREK before 5.1.1 keeps that version's app in its service
worker. When the app opened /native-handoff, the worker answered it from its
cache with an app that has no such page, which sent the user to /, and the
sign-in ended on the dashboard in the browser instead of in the app.

The app now opens /api/auth/native/start, which every TREK service worker
passes to the server. That page takes the workers off the browser and
forwards to the handoff page. Until the sign-in is handed back, the web app
registers no service worker and does not reload for a new version: a tab
still open on the older TREK keeps its worker alive, and a registration or a
reload in the middle of the sign-in brought it back to answer the next page.
This commit is contained in:
Maurice
2026-11-09 22:21:09 +01:00
parent 5420077b98
commit 034cfb539a
14 changed files with 286 additions and 7 deletions
@@ -102,6 +102,7 @@ describe('useNativeHandoff', () => {
it('FE-NATIVE-HANDOFF-006: only mints the code on the tap, then hands it to the app scheme', async () => {
vi.mocked(requestHandoffCode).mockResolvedValue('c/1');
localStorage.setItem('trek_native_signin', String(Date.now()));
const { result } = renderHandoff();
expect(requestHandoffCode).not.toHaveBeenCalled();
@@ -111,6 +112,8 @@ describe('useNativeHandoff', () => {
expect(requestHandoffCode).toHaveBeenCalledWith(challenge);
expect(window.location.href).toBe('com.liketrek.trek://auth?code=c%2F1');
// Handed back: the browser registers its service worker again from here.
expect(localStorage.getItem('trek_native_signin')).toBeNull();
});
it('FE-NATIVE-HANDOFF-007: reports a failed hand-off', async () => {
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router';
import { useShallow } from 'zustand/react/shallow';
import { HANDOFF_PATH, rememberHandoffReturn, requestHandoffCode, signInWithPasskey } from '../../native/browserSignIn';
import { endBrowserSignIn } from '../../native/browserSignInFlag';
import { APP_URL_SCHEME } from '../../native/trekShell';
import { useAuthStore } from '../../store/authStore';
@@ -50,6 +51,7 @@ export function useNativeHandoff() {
setStatus('sending');
try {
const code = await requestHandoffCode(challenge);
endBrowserSignIn();
window.location.href = `${APP_URL_SCHEME}://auth?code=${encodeURIComponent(code)}`;
} catch {
setStatus('failed');