Skip to content

fix: refresh profile after email verification - #27

Closed
bluewandd wants to merge 3 commits into
aervxa:mainfrom
bluewandd:pr/lepse-email-verification
Closed

fix: refresh profile after email verification#27
bluewandd wants to merge 3 commits into
aervxa:mainfrom
bluewandd:pr/lepse-email-verification

Conversation

@bluewandd

@bluewandd bluewandd commented Sep 2, 2026

Copy link
Copy Markdown

An unverified user can verify in another tab or window while an open Lachesis window keeps the stale profile, so its banner and gates remain visible.

The fix, two parts.

  1. useAuth.ts opts the profile query back in with a conditional refetchOnWindowFocus, which stops opting in once emailVerified is true. The query client sets refetchOnWindowFocus: false globally because refetches are manual, so the built-in never fired for this query.

  2. A new plugins/focus.ts feeds Tauri's window_focus event into focusManager.setFocused, then hands detection straight back to the default.

Why part 2 is needed. Baseline first: with only part 1, against the installed TanStack Query 5.102.8, a focused harness refetched on hidden-to-visible and did not react to a bare window focus event. The stock listener subscribes to visibilitychange only. So the browser tab-return path already worked, and the app window regaining native focus while it stays visible did not.

The library's own focus listener is left exactly as it ships. setFocused(true) reports the one signal it cannot see, and setFocused(undefined) immediately returns detection to the default rather than pinning it to a manual value.

Scope. refetchOnWindowFocus: false and refetchOnMount: false stay as they are. plugins/clotho.ts is untouched. This changes when focus is observed, not which queries react to it, so no query other than the profile one is affected. No new dependencies; @tauri-apps/api is already used for this.

Not verified on a desktop build. The browser path was measured; a real Tauri native focus event has not been exercised.

@bluewandd

bluewandd commented Sep 2, 2026

Copy link
Copy Markdown
Author

Superseded. This PR has been rewritten as a single independent change against current main, and no longer belongs to a sequence or requires any particular merge order.

The earlier branch was based on 7e8c988 and is gone. The new commit is 3 files, +25/-5, and touches only the profile query lifecycle, the focus listener, and the startup prefetch. See the updated description.

@bluewandd
bluewandd force-pushed the pr/lepse-email-verification branch from 260fe99 to 5a576a7 Compare September 6, 2026 07:34
@bluewandd bluewandd changed the title feat: add email verification fix: refresh profile after email verification Sep 6, 2026
@aervxa

aervxa commented Sep 8, 2026

Copy link
Copy Markdown
Owner

tanstack's refetchOnFocus should do this ?

@bluewandd
bluewandd force-pushed the pr/lepse-email-verification branch from 5a576a7 to 383ca37 Compare September 8, 2026 11:45
@bluewandd

Copy link
Copy Markdown
Author

Yes — that's all it needed. It's now just a per-query refetchOnWindowFocus on the profile, conditional so it stops once emailVerified is true. The global refetchOnWindowFocus: false in the query client is why the built-in wasn't firing.

Dropped the global focus listener and the token guards, so this is one file now.

One thing worth flagging: 5.102.8's default focus listener subscribes to visibilitychange only, so returning to a hidden tab is covered but a Tauri window regaining native focus while it stays visible is not. Left that as a separate issue rather than adding anything here.

@aervxa

aervxa commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Correct, but data?.data? is redundant, data?.data.xxx is correct

ps. ur correct, it won't work for an app, and the fix is specified in the respective docs

@bluewandd

Copy link
Copy Markdown
Author

Fixed in 7876963 — dropped the inner ?.. Typecheck passes.

@bluewandd

Copy link
Copy Markdown
Author

Sorry, I skipped your second line.

You're right, and thanks for the pointer: https://tanstack.com/query/latest/docs/framework/react/guides/window-focus-refetching#custom-window-focus-event — for the desktop app the documented fix is focusManager.setEventListener with a Tauri focus source, since the stock listener only watches visibilitychange.

Happy to open that as its own PR if you want it. Keeping it out of this one.

@bluewandd

Copy link
Copy Markdown
Author

Added it here in 1cd8a21 rather than a separate PR, since you said this is what's blocking the merge — say the word if you'd rather have it split and I'll move it out.

plugins/clotho.ts, following the docs: the stock visibilitychange default kept as-is, plus onFocusChanged from getCurrentWebviewWindow() behind isTauri(), same trio you already use in layouts/shell.vue. refetchOnWindowFocus: false and refetchOnMount: false are untouched, so this changes when focus is observed, not which queries react to it — only the profile query opts in.

Typecheck and lint pass. Description updated with the baseline.

@aervxa

aervxa commented Sep 9, 2026

Copy link
Copy Markdown
Owner

why not listen to https://v2.tauri.app/reference/javascript/api/namespaceevent/#window_focus and run focusManager.setFocused ?
handle the setting back to default on ur own

@bluewandd
bluewandd force-pushed the pr/lepse-email-verification branch from 1cd8a21 to 12f6bb9 Compare September 9, 2026 06:55
@bluewandd

bluewandd commented Sep 9, 2026

Copy link
Copy Markdown
Author

Done, 103338a — much better, thanks.

if (isTauri()) {
  listen(TauriEvent.WINDOW_FOCUS, () => {
    focusManager.setFocused(true)
    focusManager.setFocused(undefined)
  })
}

setEventListener is gone, so the library's own listener is untouched and none of its behaviour is reimplemented here. Description updated.

Lachesis typecheck and lint are clean. apps/clotho has 3 lint errors on files this branch doesn't touch — they're on main too, so I've left them alone.

@bluewandd
bluewandd force-pushed the pr/lepse-email-verification branch from 12f6bb9 to 103338a Compare September 9, 2026 07:01
@aervxa

aervxa commented Sep 9, 2026

Copy link
Copy Markdown
Owner

focusManager modification shouldn't be inside the clotho plugin, it's out of scope for that file.

and also, this needs testing.

tanstack's stock focus listener subscribes to `visibilitychange` only, so
returning to a browser tab revalidates but a tauri window regaining native
focus while it stays visible does not.

listen for `tauri://focus` and push that focus into the focus manager, then
set it back to undefined so detection is handed straight back to the library
default.
@bluewandd
bluewandd force-pushed the pr/lepse-email-verification branch from 103338a to 1d2cb3d Compare September 9, 2026 07:06
@bluewandd

Copy link
Copy Markdown
Author

Fair, moving it into its own plugin now — clotho.ts goes back to untouched.

On testing, what did you have in mind? There's no test runner in the repo, so I didn't want to drag vitest in for eight lines without asking first. And I can't trigger a real tauri window focus from where I'm working, so I can't honestly say I've verified it — only that the browser path behaves as expected.

Happy to do either, just say which.

@bluewandd

Copy link
Copy Markdown
Author

Moved — 1d2cb3d. It's plugins/focus.ts now, and clotho.ts is byte-identical to main again. Two files total.

@bluewandd

Copy link
Copy Markdown
Author

no rush — just flagging the testing question is still open on my side.

if you meant an automated test, the blocker is there's no runner in the repo, so it'd mean adding vitest + happy-dom for two files. happy to do it if you want it, but that's a bigger change than the fix and I didn't want to sneak it in.

if you meant you'll just try it yourself: build, open a second window, verify the email, click back onto the app window — banner should clear without a reload. that's the whole thing.

whichever you prefer.

@aervxa

aervxa commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Closed in favor of c51beb8

@aervxa aervxa closed this Sep 10, 2026
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.

3 participants