Commit graph

5 commits

Author SHA1 Message Date
Huang Xin
314a62d117
feat(koplugin): sign in with a QR code; fix the logged-out label and global logout (#7186) (#7192)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* feat(koplugin): sign in to Readest with a QR code (#7186)

Readest > Log in Readest Account now offers "Sign in with a code", the
device-code flow the CrossPoint plugin uses. KOReader shows a QR code,
the /link URL and a code. A phone signed in to Readest scans it and
approves the code on /link, and KOReader receives an ordinary Readest
session that refreshes as a password login does. Nothing is typed on
the e-reader, and accounts that sign in with Google or Apple, which
have no password, can now use the plugin.

- /api/crosspoint/device/token: with grant "session", an approved code
  returns the user's Supabase session instead of a CrossPoint key. The
  session comes from an admin magic link verified on the server; the
  link is never sent. If the session can't be started, the approval is
  put back for the next poll, as for keys.
- Plugin: requestDeviceCode/pollDeviceToken in the sync API spec.
  Polling stops on approval, on expiry, or when the code message is
  dismissed. A network failure keeps it polling. The new session is
  written to disk at once, like a refreshed one.
- /link says "Link a Reader", since KOReader uses it too.

Verified:
- crosspoint-routes.test.ts "signs KOReader in with a session of its
  own once the code is approved" fails on main (expected 500 to be
  200) and passes. syncauth_spec.lua "SyncAuth:loginWithCode" (4 specs)
  covers approval, expiry, network failure and dismissal.
- pnpm test: 1215 files, 14467 tests passed. pnpm lint: clean (tsc,
  Biome). pnpm test:lua: 495 successes. pnpm lint:lua: clean.
- Kindle (KOReader), plugin built from this branch against a local
  dev server: Log in > Sign in with a code showed the QR code and code.
  The code was approved on web.readest.com/link, the next poll returned
  200, the menu read "Log out as <user>", and opening Readest library
  synced (runCloudSync[both] done: success=true, 90 books pulled).
  After restarting KOReader it was still signed in.
- The e2e run found two bugs, fixed here: the closed menu was refreshed
  after sign-in and came back under the next tap (it toggled Auto
  sync), and the session was lost on an exit that skipped saving.
- Not run: Android KOReader, and the production host (the QR there
  encodes web.readest.com/link?code=…; the dev server's encoded
  0.0.0.0:3010).

Reported by misc-tw on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(koplugin): keep showing the account while a refresh token can renew the session (#7186)

Tools > Readest offered "Log in Readest Account" as soon as the access
token expired, although the saved refresh token renews it on the next
sync. A night in standby outlasts the token, so the plugin looked
logged out every morning and the menu asked for the password again.
needsLogin now asks for a login only while authentication is paused or
no refresh token is saved.

Verified:
- New spec "SyncAuth:needsLogin stays signed in when only the access
  token expired (#7186)" fails on main (needsLogin returned true for a
  token expired 8 h ago) and passes with the fix.
- pnpm test:lua: 493 successes, 0 failures. pnpm lint:lua: clean.
- Kindle (KOReader, plugin 0.12.16) with an access token expired 8.5
  days earlier and its refresh token saved: Tools > Readest showed
  "Log in Readest Account". With the fixed readest_syncauth.lua pushed
  and KOReader restarted, it showed "Log out as <user>"; Pull stats now
  then renewed the token (expires_at moved to now + 60457 s) with no
  login.
- Not run: the reporter's BOOX Go 7 Color (Android).

Reported by misc-tw on GitHub.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(koplugin): log out only this device, like the Readest app

Readest > Log out called Supabase /logout without a scope. Supabase's
default scope is global, so logging out of KOReader also ended every
other session of the account (app, web, other readers) at their next
token refresh. The app signs out with scope "local" (#6709); the plugin
now sends the same.

Verified:
- New spec "SupabaseAuthClient:sign_out signs out only this device"
  fails on main (no params sent; expected { scope = "local" }) and
  passes with the fix.
- The request KOReader's Spore library builds from the spec:
  main  POST .../auth/v1/logout
  fix   POST .../auth/v1/logout?scope=local
- Kindle (KOReader): signed in, opened a second session of the same
  account from a shell, then Log out in the plugin. The menu went back
  to "Log in Readest Account" and the second session still refreshed
  (HTTP 200); it was then signed out with scope=local.
- pnpm test:lua: 492 successes, 0 failures. pnpm lint:lua: clean.
- Not run: the global-scope logout on main against a live account, to
  avoid signing the account out everywhere.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 04:01:53 +01:00
ivanovsergey93
915cd3bd43
fix(koreader): reliable progress sync with hardened auth and error handling (#6684)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
Publish Docker image / build (linux/amd64, ubuntu-latest) (push) Waiting to run
Publish Docker image / build (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Publish Docker image / merge (push) Blocked by required conditions
Build with Nix / tests (push) Waiting to run
PR checks / nix_flake_check (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / koplugin_rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (1) (push) Waiting to run
PR checks / test_web_app (2) (push) Waiting to run
PR checks / test_extensions (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
* fix(koreader): improve reading progress sync

* docs(koreader): document progress sync behavior and limitations

* fix(koreader): harden sync auth, conflict handling, and error reporting

* fix(koreader): keep non-auth 403 reasons and report the failed library sync step

* fix(koreader): move backward on manual pull only to an exact position

A manual pull could jump back when the remote xpointer only resolved
after trimming to a parent node (a chapter start or /body), since a
parent orders before its children. Manual pulls still go backward to an
exact page or an xpointer that resolves untrimmed; a trimmed xpointer
only ever moves forward. Automatic pulls stay forward-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* i18n(koreader): translate sync error messages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(koreader): report a pulled position whose chapter is missing

Trimming an unresolvable xpointer fell back to /body, which resolves in
any book, so a pull reported success for a position it could not use.
Stop trimming above /body so such positions count as unusable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Sergey Ivanov <sergejs.ivanovs@applyit.lv>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 13:31:01 +02:00
Huang Xin
489eb705d6
fix(koplugin): prompt to log in again when the session has expired (#6445)
* fix(koplugin): prompt to log in again when the session has expired

When Supabase rejects the refresh token (session revoked, signed out
elsewhere, password changed, or expired), every later sync call failed
with a bare "auth refresh failed" and the plugin never asked the user to
sign in again, so uploads and syncs stayed broken until they logged out
and back in by hand.

The refresh callback now carries the HTTP status. A status means the
auth server answered and turned the token down: clear the dead tokens
(keeping the email for the login form) and show a prompt that opens the
login dialog. With no status the request never got an answer, so the
session is kept for the next try. tryRefreshToken now goes through the
same path instead of only logging the failure.

Closes #6428

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(koplugin): expire only on a token rejection that is still current

Expire the session only for 400/401/403 from the token endpoint, so a
429 or 5xx that reaches the callback keeps a valid refresh token. Pass
the rejected refresh token to expireSession and clear the session only
if it still matches, so a stale rejection cannot wipe tokens a
concurrent refresh has just saved.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 05:02:30 +02:00
JemyZhang
6e4867c866
fix(koplugin): guard nil response on login/OTP failure (#5507)
* fix(koplugin): guard nil response on login/OTP failure

sign_in_password and verify_otp returned res.body as the second value on
pcall failure, which is nil when res is an error string. doLogin then
indexed response.msg on the nil value, crashing KOReader when the network
request failed during login.

Return a table with the error message from the auth client, and guard the
caller against a nil response.

* fix(koplugin): normalize auth failures for every Supabase endpoint

The nil response was not unique to sign_in_password and verify_otp: all
six endpoints repeat the same pcall failure branch and return res.body,
which is nil whenever res is an error string, because indexing a string
with .body silently yields nil instead of raising.

refresh_token is a live path used by tryRefreshToken and withFreshToken.
It does not crash, since both callers guard, but the failure log printed
"Unknown error" and swallowed the real network cause.

Funnel every endpoint through a single unwrap() helper so the second
return value is always a table callers can read .msg off, which also
covers a decoded body coming back nil on an expected error status.

Add specs for the raised-request path and for SyncAuth:doLogin; both
fail on the previous code with "attempt to index local 'response'
(a nil value)".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Jemy Zhang <jemy.zhang@localhost>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-05 09:10:48 +02:00
Jon Volkmar
f6b6281160
fix(kosync): add namespace to koreader plugin modules to avoid collision (#4153)
Some checks are pending
CodeQL Advanced / Analyze (actions) (push) Waiting to run
CodeQL Advanced / Analyze (javascript-typescript) (push) Waiting to run
CodeQL Advanced / Analyze (rust) (push) Waiting to run
PR checks / rust_lint (push) Waiting to run
PR checks / build_web_app (push) Waiting to run
PR checks / test_web_app (push) Waiting to run
PR checks / build_tauri_app (push) Waiting to run
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
2026-05-14 08:56:36 +08:00
Renamed from apps/readest.koplugin/syncauth.lua (Browse further)