Skip to content

Android: complete the 2FA login flow and fix unreadable login form in dark mode - #414

Merged
Dvorinka merged 2 commits into
Dvorinka:masterfrom
dxts:fix/android-2fa-login
Nov 2, 2026
Merged

Dvorinka merged 2 commits into
Dvorinka:masterfrom
dxts:fix/android-2fa-login

Conversation

@dxts

@dxts dxts commented Nov 2, 2026

Copy link
Copy Markdown

Two Android login fixes, one commit each.

1. Complete the two-factor login flow

Enabling TOTP on an account locks the Android app out. With 2FA on, the server answers POST /api/v4/session/token with code: 203 (CodeNotFullySuccess) and the 2FA session id in data, expecting a follow-up POST /api/v4/session/token/2fa with {otp, session_id} within ten minutes (routers/controllers/user.go UserLoginValidation, service/user/login.go Verify2FA). The app treated every non-zero code as a failed login, so the only way in was the browser OAuth flow, and nothing told the user that.

Changes:

  • login() decodes data as JsonElement, since it is either a LoginResponse or the 2FA session id string.
  • On 203 the session id is kept in UI state and the form switches to a 6-digit code step (TwoFactorStep), digits only, submit enabled at six.
  • verify2FA() posts {otp, session_id}; success saves the session exactly as a plain login does. 404 means the ten-minute 2FA session expired and returns the user to the password form; any other error keeps the code step and shows the server message.
  • Back button abandons the challenge.

The OAuth/browser sign-in and the refresh path are untouched.

2. Fix the unreadable login form in dark mode

The login form rendered light-grey text on a light background in dark mode. Nothing in the Compose tree painted a background: App() goes CloudreveTheme → NavHost → LoginScreen → Column with no Surface/Scaffold, so the window colour came from themes.xml, hard-coded to Theme.Material.Light, while CloudreveTheme followed the system and picked the dark scheme's text colours. Text and background were coming from two themes that disagreed.

Changes:

  • CloudreveTheme wraps content in a Surface painted with the scheme's background/onBackground, so Compose text always sits on Compose's own surface regardless of the window theme.
  • Both schemes now set the full background/surface/surfaceVariant pairs with their on* colours and outline, rather than overriding surface alone and inheriting defaults tuned for a different surface. Every text/background pair is ≥ 4.5:1 (WCAG AA); onSurface on dark surface is 14.6:1.
  • values-night/themes.xml + values-night/colors.xml give the window a dark variant with a matching windowBackground, so the splash and edge-to-edge insets agree with the scheme too.

Testing

Could not run a Gradle build in this environment (no Android SDK on the machine the fix was written on), so please run the usual build/lint. Logic was verified against the server contract in this repo; the contrast numbers were computed from the hex values.

Dixit Sabharwal added 2 commits November 2, 2026 09:48
When an account has TOTP enabled the server answers the password login with
code 203 (CodeNotFullySuccess) and a 2FA session id in `data`, expecting a
follow-up POST /api/v4/session/token/2fa with {otp, session_id}. The app
treated every non-zero code as a failed login, so turning on 2FA locked
users out of the app entirely; the only way back in was the browser flow.

- Decode the login response's `data` as JsonElement, since it is either a
  LoginResponse or the 2FA session id string.
- On 203, keep the session id in UI state and show a 6-digit code step.
- verify2FA() posts the code; a 404 means the ten-minute 2FA session
  expired and returns the user to the password form.
- Back button abandons the challenge.
Nothing in the Compose tree painted a background: App() went
CloudreveTheme -> NavHost -> LoginScreen -> Column with no Surface, so the
window colour came from themes.xml, hard-coded to Theme.Material.Light,
while CloudreveTheme followed the system and picked dark-scheme text
colours. In dark mode that put light-grey text on a light window.

- CloudreveTheme wraps content in a Surface painted with the scheme's
  background/onBackground, so Compose text always sits on Compose's own
  surface.
- Set the full surface/background pairs with their on* colours in both
  schemes instead of overriding surface alone (every pair >= 4.5:1).
- values-night/themes.xml gives the window a dark variant and a matching
  windowBackground, so the splash and edge-to-edge insets agree with the
  scheme too.
@mira-tdvorak

mira-tdvorak Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Mira PR Walkthrough

This PR implements two distinct Android fixes: (1) Completes the 2FA/TOTP login flow by handling the server's 203 response code, adding a 6-digit code entry step, and calling the verification endpoint; (2) Fixes dark mode readability by wrapping Compose content in a Surface with proper background/onBackground colors, and adding night theme XML resources so window background matches the Compose color scheme.

Confidence: 4/5   ◉◉◉◉○   Safe with minor fixes
  • Changes are well-scoped and logic is sound, but the PR author notes they couldn't run Gradle builds/lint; CI should verify the Android build compiles and the theme changes don't introduce regressions.

9 files reviewed


Comment @mira-tdvorak help to get the list of available commands and usage tips.

@Dvorinka
Dvorinka merged commit d74bf04 into Dvorinka:master Nov 2, 2026
@Dvorinka Dvorinka mentioned this pull request Nov 2, 2026
Dvorinka pushed a commit that referenced this pull request Nov 5, 2026
#414 added a second companion object for the 2FA result codes, but the
class already had one holding the OAuth constants. Kotlin allows only one
per class, so compileDebugKotlin failed with "Only one companion object is
allowed per class" and unresolved OAUTH_* references. Move the two constants
into the existing companion object. Verified with ./gradlew :app:assembleDebug
on JDK 21.
Dvorinka added a commit that referenced this pull request Nov 5, 2026
Android: fix compile error from duplicate companion object (#414 follow-up)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants