Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(login): keep the app sign-in screen within the eslint ratchets

Maurice742c0dd72d97
diff --git a/client/src/native/appBoot.test.ts b/client/src/native/appBoot.test.ts
index 73c3b0f8f..ed0a3e955 100644
--- a/client/src/native/appBoot.test.ts
+++ b/client/src/native/appBoot.test.ts
@@ -72,7 +72,6 @@ describe('appBoot', () => {
it('FE-NATIVE-APPBOOT-004: does not wait for settings that never come, nor stop on ones that fail', async () => {
vi.useFakeTimers();
- vi.spyOn(console, 'warn').mockImplementation(() => {});
const hanging = vi.fn();
void handOverToApp(new Promise(() => {}), hanging);
await vi.advanceTimersByTimeAsync(1600);
diff --git a/client/src/native/appBoot.ts b/client/src/native/appBoot.ts
index 310bbb694..a9e17f851 100644
--- a/client/src/native/appBoot.ts
+++ b/client/src/native/appBoot.ts
@@ -42,10 +42,8 @@ const wait = (ms: number): Promise<void> => new Promise((resolve) => window.setT
* the app, which rises in once its first screen is there (endAppBoot).
*/
export function handOverToApp(settings: Promise<unknown>, go: () => void): Promise<void> {
- const ready = Promise.race([settings, wait(SETTINGS_WAIT_MS)]).then(
- () => undefined,
- (err: unknown) => console.warn('Settings not ready for the handover:', err)
- );
+ // allSettled: settings that fail to load must not hold the app back either.
+ const ready = Promise.race([Promise.allSettled([settings]), wait(SETTINGS_WAIT_MS)]);
return Promise.all([ready, wait(LEAVE_MS)]).then(() => {
document.documentElement.setAttribute(HANDOVER, '');
go();
diff --git a/client/src/pages/login/AppLogin.tsx b/client/src/pages/login/AppLogin.tsx
index ed58a8dc2..399ad70d8 100644
--- a/client/src/pages/login/AppLogin.tsx
+++ b/client/src/pages/login/AppLogin.tsx
@@ -5,9 +5,10 @@ import { useNativeServer } from '../../components/Settings/useNativeServer';
import PasswordChecklist from '../../components/shared/PasswordChecklist';
import { useTranslation } from '../../i18n';
import { lightStatusBarIcons } from '../../native/appBoot';
+import { reportNativeFailure } from '../../native/reportFailure';
import './appLogin.css';
import { heading as headingOf, oidcLoginHref, oidcOnlyHref, submitLabel, type LoginStep } from './loginModel';
-import { mfaCodeInputProps } from './MfaCodeStep';
+import { mfaCodeInputProps } from './mfaCodeInput';
import { IDP_LOGIN_URL, type useLogin } from './useLogin';
type Login = ReturnType<typeof useLogin>;
@@ -75,7 +76,8 @@ function AppLoginHero() {
.then(({ startScenery, cameraForPlan }) => {
if (!cancelled) startScenery(box, { frame: 320, camera: cameraForPlan(1), haze: false });
})
- .catch((err: unknown) => console.warn('Landscape unavailable:', err));
+ // Without the landscape the box keeps its plain sea colour.
+ .catch(reportNativeFailure);
return () => {
cancelled = true;
box.querySelector('canvas.scenery')?.remove();
@@ -168,7 +170,7 @@ function Credentials({ login }: { login: Login }) {
const onAccount = !(login.mode === 'login' && login.mfaStep) && !login.passwordChangeStep;
return (
<>
- <form className="al-form" onSubmit={login.handleSubmit}>
+ <form className="al-form" onSubmit={(e) => void login.handleSubmit(e)}>
<h1 className="al-title">{heading.title}</h1>
{/* The plain sign-in needs no line under its heading; the other steps say what they ask for. */}
{!heading.plain && <p className="al-sub">{heading.subtitle}</p>}
@@ -184,7 +186,7 @@ function Credentials({ login }: { login: Login }) {
<OtherWays login={login} />
<ModeSwitch login={login} />
{login.mode === 'login' && onAccount && (
- <button type="button" className="al-forgot" onClick={() => login.navigate('/forgot-password')}>
+ <button type="button" className="al-forgot" onClick={() => void login.navigate('/forgot-password')}>
{t('login.forgotPassword')}
</button>
)}
@@ -340,40 +342,44 @@ function LoginOptions({ login }: { login: Login }) {
);
}
+/** Which of the ways in besides the password this server offers on this step. */
+function otherWaysOf(login: Login): { sso: boolean; passkey: boolean; demo: boolean } {
+ const config = login.appConfig;
+ const onFirstStep = login.mode === 'login' && !login.mfaStep && !login.passwordChangeStep;
+ return {
+ sso: !!(config?.oidc_configured && config.oidc_login && !login.oidcOnly),
+ passkey: !!(config?.passkey_login && config.passkey_configured && onFirstStep),
+ demo: !!config?.demo_mode,
+ };
+}
+
/** SSO, a passkey and the demo: the ways in besides the password. */
function OtherWays({ login }: { login: Login }) {
const { t } = useTranslation();
- const config = login.appConfig;
- const sso = !!(config?.oidc_configured && config?.oidc_login && !login.oidcOnly);
- const passkey = !!(
- config?.passkey_login &&
- config?.passkey_configured &&
- login.mode === 'login' &&
- !login.mfaStep &&
- !login.passwordChangeStep
- );
- if (!sso && !passkey && !config?.demo_mode) return null;
+ const ways = otherWaysOf(login);
+ if (!ways.sso && !ways.passkey && !ways.demo) return null;
return (
<div className="al-alt">
- {(sso || passkey) && <div className="al-or">{t('common.or')}</div>}
- {sso && (
- <a
+ {(ways.sso || ways.passkey) && <div className="al-or">{t('common.or')}</div>}
+ {ways.sso && <SsoButton login={login} />}
+ {ways.passkey && (
+ <button
+ type="button"
className="al-cta2"
- href={oidcLoginHref(login.inviteToken, login.mode, login.rememberMe)}
- onClick={login.handleSsoClick}
+ onClick={() => void login.handlePasskeyLogin()}
+ disabled={login.isLoading}
>
- <Shield size={18} aria-hidden="true" />
- {t('login.oidcSignIn', { name: config?.oidc_display_name || 'SSO' })}
- </a>
- )}
- {passkey && (
- <button type="button" className="al-cta2" onClick={login.handlePasskeyLogin} disabled={login.isLoading}>
<Fingerprint size={18} aria-hidden="true" />
{t('login.passkey.signIn')}
</button>
)}
- {config?.demo_mode && (
- <button type="button" className="al-cta al-demo" onClick={login.handleDemoLogin} disabled={login.isLoading}>
+ {ways.demo && (
+ <button
+ type="button"
+ className="al-cta al-demo"
+ onClick={() => void login.handleDemoLogin()}
+ disabled={login.isLoading}
+ >
{t('login.demoHint')}
</button>
)}
@@ -381,6 +387,20 @@ function OtherWays({ login }: { login: Login }) {
);
}
+function SsoButton({ login }: { login: Login }) {
+ const { t } = useTranslation();
+ return (
+ <a
+ className="al-cta2"
+ href={oidcLoginHref(login.inviteToken, login.mode, login.rememberMe)}
+ onClick={login.handleSsoClick}
+ >
+ <Shield size={18} aria-hidden="true" />
+ {t('login.oidcSignIn', { name: login.appConfig?.oidc_display_name || 'SSO' })}
+ </a>
+ );
+}
+
function ModeSwitch({ login }: { login: Login }) {
const { t } = useTranslation();
const config = login.appConfig;
diff --git a/client/src/pages/login/MfaCodeStep.tsx b/client/src/pages/login/MfaCodeStep.tsx
index e672028f0..0261a3a74 100644
--- a/client/src/pages/login/MfaCodeStep.tsx
+++ b/client/src/pages/login/MfaCodeStep.tsx
@@ -1,6 +1,7 @@
import { KeyRound } from 'lucide-react';
import React from 'react';
import { useTranslation } from '../../i18n';
+import { mfaCodeInputProps } from './mfaCodeInput';
interface MfaCodeStepProps {
/** The account being signed in, kept in the form for password managers. */
@@ -11,35 +12,6 @@ interface MfaCodeStepProps {
onBack: () => void;
}
-/**
- * The one-time code field, for this step and the app's sign-in screen alike.
- * Text, not numeric: backup codes carry letters. The hints are set here rather
- * than left to native/keyboardFields.ts, because autoFocus gives the field
- * focus before any touch could prepare it.
- */
-export function mfaCodeInputProps(
- code: string,
- onCode: (code: string) => void,
- placeholder: string
-): React.InputHTMLAttributes<HTMLInputElement> {
- return {
- type: 'text',
- id: 'totp',
- name: 'totp',
- inputMode: 'text',
- autoComplete: 'one-time-code',
- autoCapitalize: 'characters',
- autoCorrect: 'off',
- spellCheck: false,
- enterKeyHint: 'go',
- value: code,
- onChange: (e: React.ChangeEvent<HTMLInputElement>) => onCode(e.target.value.toUpperCase().slice(0, 24)),
- placeholder,
- required: true,
- autoFocus: true,
- };
-}
-
/** The login's second step: the one-time or backup code, and the way back. */
export default function MfaCodeStep({ email, code, onCode, inputStyle, onBack }: MfaCodeStepProps) {
const { t } = useTranslation();
diff --git a/client/src/pages/login/mfaCodeInput.ts b/client/src/pages/login/mfaCodeInput.ts
new file mode 100644
index 000000000..db9dc7344
--- /dev/null
+++ b/client/src/pages/login/mfaCodeInput.ts
@@ -0,0 +1,30 @@
+import type React from 'react';
+
+/**
+ * The one-time code field, for this step and the app's sign-in screen alike.
+ * Text, not numeric: backup codes carry letters. The hints are set here rather
+ * than left to native/keyboardFields.ts, because autoFocus gives the field
+ * focus before any touch could prepare it.
+ */
+export function mfaCodeInputProps(
+ code: string,
+ onCode: (code: string) => void,
+ placeholder: string
+): React.InputHTMLAttributes<HTMLInputElement> {
+ return {
+ type: 'text',
+ id: 'totp',
+ name: 'totp',
+ inputMode: 'text',
+ autoComplete: 'one-time-code',
+ autoCapitalize: 'characters',
+ autoCorrect: 'off',
+ spellCheck: false,
+ enterKeyHint: 'go',
+ value: code,
+ onChange: (e: React.ChangeEvent<HTMLInputElement>) => onCode(e.target.value.toUpperCase().slice(0, 24)),
+ placeholder,
+ required: true,
+ autoFocus: true,
+ };
+}
diff --git a/client/src/pages/login/useLogin.ts b/client/src/pages/login/useLogin.ts
index 26f022efa..d0b6af259 100644
--- a/client/src/pages/login/useLogin.ts
+++ b/client/src/pages/login/useLogin.ts
@@ -170,7 +170,9 @@ export function useLogin() {
// The app has no takeoff: the sign-in screen steps back and the app rises in
// as soon as the settings are there (native/appBoot.ts).
toastHaptic('success')
- void handOverToApp(loadSettings(), () => navigate(redirectTarget))
+ void handOverToApp(loadSettings(), () => {
+ void navigate(redirectTarget)
+ })
return
}
loadSettings()